PageRenderTime 54ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/propal/addpropal.php

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