PageRenderTime 59ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/comm/addpropal.php

https://github.com/asterix14/dolibarr
PHP | 347 lines | 236 code | 55 blank | 56 comment | 38 complexity | fb96d65837b9e0bf6e05cb7852ea9cfe MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr>
  5. * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
  6. * Copyright (C) 2011 Philippe Grand <philippe.grand@atoo-net.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/comm/addpropal.php
  23. * \ingroup propal
  24. * \brief Page to add a new commercial proposal
  25. */
  26. require("../main.inc.php");
  27. require_once(DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php');
  28. require_once(DOL_DOCUMENT_ROOT.'/core/modules/propale/modules_propale.php');
  29. if ($conf->projet->enabled)
  30. {
  31. require_once(DOL_DOCUMENT_ROOT."/projet/class/project.class.php");
  32. require_once(DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php');
  33. }
  34. $langs->load("propal");
  35. if ($conf->projet->enabled) $langs->load("projects");
  36. $langs->load("companies");
  37. $langs->load("bills");
  38. $langs->load("orders");
  39. $langs->load("deliveries");
  40. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  41. include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
  42. $hookmanager=new HookManager($db);
  43. $hookmanager->callHooks(array('propalcard'));
  44. /*
  45. * Actions
  46. */
  47. // None
  48. /*
  49. * View
  50. */
  51. llxHeader();
  52. print_fiche_titre($langs->trans("NewProp"));
  53. $form=new Form($db);
  54. // Add new proposal
  55. if ($_GET["action"] == 'create')
  56. {
  57. $soc = new Societe($db);
  58. $result=$soc->fetch($_GET["socid"]);
  59. if ($result < 0)
  60. {
  61. dol_print_error($db,$soc->error);
  62. exit;
  63. }
  64. $propal = new Propal($db);
  65. $numpr='';
  66. $obj = $conf->global->PROPALE_ADDON;
  67. if ($obj)
  68. {
  69. if (! empty($conf->global->PROPALE_ADDON) && is_readable(DOL_DOCUMENT_ROOT ."/core/modules/propale/".$conf->global->PROPALE_ADDON.".php"))
  70. {
  71. require_once(DOL_DOCUMENT_ROOT ."/core/modules/propale/".$conf->global->PROPALE_ADDON.".php");
  72. $modPropale = new $obj;
  73. $numpr = $modPropale->getNextValue($soc,$propal);
  74. }
  75. }
  76. // Fix pour modele numerotation qui deconne
  77. // Si numero deja pris (ne devrait pas arriver), on incremente par .num+1
  78. $sql = "SELECT count(*) as nb";
  79. $sql.= " FROM ".MAIN_DB_PREFIX."propal";
  80. $sql.= " WHERE ref LIKE '".$numpr."%'";
  81. $sql.= " AND entity = ".$conf->entity;
  82. $resql=$db->query($sql);
  83. if ($resql)
  84. {
  85. $obj=$db->fetch_object($resql);
  86. $num = $obj->nb;
  87. $db->free($resql);
  88. if ($num > 0)
  89. {
  90. $numpr .= "." . ($num + 1);
  91. }
  92. }
  93. print '<form name="addprop" action="propal.php?socid='.$soc->id.'" method="POST">';
  94. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  95. print '<input type="hidden" name="action" value="add">';
  96. if (isset($_GET["origin"]) && $_GET["origin"] != 'project' && isset($_GET["originid"]))
  97. {
  98. print '<input type="hidden" name="origin" value="'.$_GET["origin"].'">';
  99. print '<input type="hidden" name="originid" value="'.$_GET["originid"].'">';
  100. }
  101. print '<table class="border" width="100%">';
  102. // Ref
  103. print '<tr><td class="fieldrequired">'.$langs->trans("Ref").'</td><td colspan="2"><input name="ref" value="'.$numpr.'"></td></tr>';
  104. // Ref customer
  105. print '<tr><td>'.$langs->trans('RefCustomer').'</td><td colspan="2">';
  106. print '<input type="text" name="ref_client" value=""></td>';
  107. print '</tr>';
  108. // Third party
  109. print '<tr><td class="fieldrequired">'.$langs->trans('Company').'</td><td colspan="2">'.$soc->getNomUrl(1);
  110. print '<input type="hidden" name="socid" value="'.$soc->id.'">';
  111. print '</td>';
  112. print '</tr>';
  113. // Contacts
  114. print "<tr><td>".$langs->trans("DefaultContact")."</td><td colspan=\"2\">\n";
  115. $form->select_contacts($soc->id,$setcontact,'contactidp',1);
  116. print '</td></tr>';
  117. // Ligne info remises tiers
  118. print '<tr><td>'.$langs->trans('Discounts').'</td><td colspan="2">';
  119. if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client);
  120. else print $langs->trans("CompanyHasNoRelativeDiscount");
  121. $absolute_discount=$soc->getAvailableDiscounts();
  122. print '. ';
  123. if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->trans("Currency".$conf->monnaie));
  124. else print $langs->trans("CompanyHasNoAbsoluteDiscount");
  125. print '.';
  126. print '</td></tr>';
  127. // Date
  128. print '<tr><td class="fieldrequired">'.$langs->trans('Date').'</td><td colspan="2">';
  129. $form->select_date('','','','','',"addprop");
  130. print '</td></tr>';
  131. // Validaty duration
  132. print '<tr><td class="fieldrequired">'.$langs->trans("ValidityDuration").'</td><td colspan="2"><input name="duree_validite" size="5" value="'.$conf->global->PROPALE_VALIDITY_DURATION.'"> '.$langs->trans("days").'</td></tr>';
  133. // Terms of payment
  134. print '<tr><td nowrap="nowrap" class="fieldrequired">'.$langs->trans('PaymentConditionsShort').'</td><td colspan="2">';
  135. $form->select_conditions_paiements($soc->cond_reglement,'cond_reglement_id');
  136. print '</td></tr>';
  137. // Mode of payment
  138. print '<tr><td>'.$langs->trans('PaymentMode').'</td><td colspan="2">';
  139. $form->select_types_paiements($soc->mode_reglement,'mode_reglement_id');
  140. print '</td></tr>';
  141. // What trigger creation
  142. print '<tr><td>'.$langs->trans('Source').'</td><td>';
  143. $form->select_demand_reason($propal->demand_reason,'demand_reason_id',"SRC_PROP",1);
  144. print '</td></tr>';
  145. // Delivery delay
  146. print '<tr><td>'.$langs->trans('AvailabilityPeriod').'</td><td colspan="2">';
  147. $form->select_availability($propal->availability,'availability_id','',1);
  148. print '</td></tr>';
  149. // Delivery date (or manufacturing)
  150. print '<tr><td>'.$langs->trans("DeliveryDate").'</td>';
  151. print '<td colspan="2">';
  152. if ($conf->global->DATE_LIVRAISON_WEEK_DELAY != "")
  153. {
  154. $tmpdte = time() + ((7 * $conf->global->DATE_LIVRAISON_WEEK_DELAY) * 24 * 60 * 60);
  155. $syear = date("Y", $tmpdte);
  156. $smonth = date("m", $tmpdte);
  157. $sday = date("d", $tmpdte);
  158. $form->select_date($syear."-".$smonth."-".$sday,'liv_','','','',"addprop");
  159. }
  160. else
  161. {
  162. $datepropal=empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0;
  163. $form->select_date($datepropal,'liv_','','','',"addprop");
  164. }
  165. print '</td></tr>';
  166. // Delivery address
  167. if ($conf->global->PROPALE_ADD_DELIVERY_ADDRESS)
  168. {
  169. print '<tr><td>'.$langs->trans('DeliveryAddress').'</td>';
  170. print '<td colspan="3">';
  171. $numaddress = $form->select_address($soc->fk_delivery_address, $_GET['socid'],'fk_address',1);
  172. if ($numaddress==0)
  173. {
  174. print ' &nbsp; <a href=../comm/address.php?socid='.$soc->id.'&action=create>'.$langs->trans("AddAddress").'</a>';
  175. }
  176. print '</td></tr>';
  177. }
  178. // Model
  179. print '<tr>';
  180. print '<td>'.$langs->trans("DefaultModel").'</td>';
  181. print '<td colspan="2">';
  182. $liste=ModelePDFPropales::liste_modeles($db);
  183. print $form->selectarray('model',$liste,$conf->global->PROPALE_ADDON_PDF);
  184. print "</td></tr>";
  185. // Project
  186. if ($conf->projet->enabled)
  187. {
  188. $projectid = 0;
  189. if (isset($_GET["origin"]) && $_GET["origin"] == 'project') $projectid = ($_GET["originid"]?$_GET["originid"]:0);
  190. print '<tr>';
  191. print '<td valign="top">'.$langs->trans("Project").'</td><td colspan="2">';
  192. $numprojet=select_projects($soc->id,$projectid);
  193. if ($numprojet==0)
  194. {
  195. print ' &nbsp; <a href="../projet/fiche.php?socid='.$soc->id.'&action=create">'.$langs->trans("AddProject").'</a>';
  196. }
  197. print '</td>';
  198. print '</tr>';
  199. }
  200. // Insert hooks
  201. $parameters=array('socid'=>$socid);
  202. $object=new Propal($db);
  203. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  204. print "</table>";
  205. print '<br>';
  206. /*
  207. * Combobox pour la fonction de copie
  208. */
  209. if (empty($conf->global->PROPAL_CLONE_ON_CREATE_PAGE))
  210. {
  211. print '<input type="hidden" name="createmode" value="empty">';
  212. }
  213. print '<table>';
  214. if (! empty($conf->global->PROPAL_CLONE_ON_CREATE_PAGE))
  215. {
  216. // For backward compatibility
  217. print '<tr>';
  218. print '<td><input type="radio" name="createmode" value="copy"></td>';
  219. print '<td>'.$langs->trans("CopyPropalFrom").' </td>';
  220. print '<td>';
  221. $liste_propal = array();
  222. $liste_propal[0] = '';
  223. $sql ="SELECT p.rowid as id, p.ref, s.nom";
  224. $sql.=" FROM ".MAIN_DB_PREFIX."propal p";
  225. $sql.= ", ".MAIN_DB_PREFIX."societe s";
  226. $sql.= " WHERE s.rowid = p.fk_soc";
  227. $sql.= " AND p.entity = ".$conf->entity;
  228. $sql.= " AND p.fk_statut <> 0";
  229. $sql.= " ORDER BY Id";
  230. $resql = $db->query($sql);
  231. if ($resql)
  232. {
  233. $num = $db->num_rows($resql);
  234. $i = 0;
  235. while ($i < $num)
  236. {
  237. $row = $db->fetch_row($resql);
  238. $propalRefAndSocName = $row[1]." - ".$row[2];
  239. $liste_propal[$row[0]]=$propalRefAndSocName;
  240. $i++;
  241. }
  242. print $form->selectarray("copie_propal",$liste_propal, 0);
  243. }
  244. else
  245. {
  246. dol_print_error($db);
  247. }
  248. print '</td></tr>';
  249. if ($conf->global->PRODUCT_SHOW_WHEN_CREATE) print '<tr><td colspan="3">&nbsp;</td></tr>';
  250. print '<tr><td valign="top"><input type="radio" name="createmode" value="empty" checked="checked"></td>';
  251. print '<td valign="top" colspan="2">'.$langs->trans("CreateEmptyPropal").'</td></tr>';
  252. }
  253. if (! empty($conf->global->PRODUCT_SHOW_WHEN_CREATE))
  254. {
  255. print '<tr><td colspan="3">';
  256. if ($conf->product->enabled || $conf->service->enabled)
  257. {
  258. $lib=$langs->trans("ProductsAndServices");
  259. print '<table class="border" width="100%">';
  260. print '<tr>';
  261. print '<td>'.$lib.'</td>';
  262. print '<td>'.$langs->trans("Qty").'</td>';
  263. print '<td>'.$langs->trans("ReductionShort").'</td>';
  264. print '</tr>';
  265. for ($i = 1 ; $i <= $conf->global->PRODUCT_SHOW_WHEN_CREATE; $i++)
  266. {
  267. print '<tr><td>';
  268. // multiprix
  269. if($conf->global->PRODUIT_MULTIPRICES && $soc->price_level)
  270. $form->select_produits('',"idprod".$i,'',$conf->product->limit_size,$soc->price_level);
  271. else
  272. $form->select_produits('',"idprod".$i,'',$conf->product->limit_size);
  273. print '</td>';
  274. print '<td><input type="text" size="2" name="qty'.$i.'" value="1"></td>';
  275. print '<td><input type="text" size="2" name="remise'.$i.'" value="'.$soc->remise_client.'">%</td>';
  276. print '</tr>';
  277. }
  278. print "</table>";
  279. }
  280. print '</td></tr>';
  281. }
  282. print '</table>';
  283. print '<br>';
  284. $langs->load("bills");
  285. print '<center>';
  286. print '<input type="submit" class="button" value="'.$langs->trans("CreateDraft").'">';
  287. print '</center>';
  288. print "</form>";
  289. }
  290. $db->close();
  291. llxFooter();
  292. ?>