PageRenderTime 771ms CodeModel.GetById 87ms app.highlight 102ms RepoModel.GetById 462ms app.codeStats 1ms

/htdocs/comm/addpropal.php

https://github.com/asterix14/dolibarr
PHP | 347 lines | 236 code | 55 blank | 56 comment | 38 complexity | fb96d65837b9e0bf6e05cb7852ea9cfe MD5 | raw file
  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/**
 23 *	\file       htdocs/comm/addpropal.php
 24 *	\ingroup    propal
 25 *	\brief      Page to add a new commercial proposal
 26 */
 27
 28require("../main.inc.php");
 29require_once(DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php');
 30require_once(DOL_DOCUMENT_ROOT.'/core/modules/propale/modules_propale.php');
 31if ($conf->projet->enabled)
 32{
 33	require_once(DOL_DOCUMENT_ROOT."/projet/class/project.class.php");
 34	require_once(DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php');
 35}
 36
 37$langs->load("propal");
 38if ($conf->projet->enabled) $langs->load("projects");
 39$langs->load("companies");
 40$langs->load("bills");
 41$langs->load("orders");
 42$langs->load("deliveries");
 43
 44// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
 45include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
 46$hookmanager=new HookManager($db);
 47$hookmanager->callHooks(array('propalcard'));
 48
 49/*
 50 * Actions
 51 */
 52
 53// None
 54
 55
 56
 57/*
 58 * View
 59 */
 60
 61llxHeader();
 62
 63print_fiche_titre($langs->trans("NewProp"));
 64
 65$form=new Form($db);
 66
 67
 68// Add new proposal
 69if ($_GET["action"] == 'create')
 70{
 71	$soc = new Societe($db);
 72	$result=$soc->fetch($_GET["socid"]);
 73	if ($result < 0)
 74	{
 75		dol_print_error($db,$soc->error);
 76		exit;
 77	}
 78
 79	$propal = new Propal($db);
 80
 81	$numpr='';
 82	$obj = $conf->global->PROPALE_ADDON;
 83	if ($obj)
 84	{
 85		if (! empty($conf->global->PROPALE_ADDON) && is_readable(DOL_DOCUMENT_ROOT ."/core/modules/propale/".$conf->global->PROPALE_ADDON.".php"))
 86		{
 87			require_once(DOL_DOCUMENT_ROOT ."/core/modules/propale/".$conf->global->PROPALE_ADDON.".php");
 88			$modPropale = new $obj;
 89			$numpr = $modPropale->getNextValue($soc,$propal);
 90		}
 91	}
 92
 93	// Fix pour modele numerotation qui deconne
 94	// Si numero deja pris (ne devrait pas arriver), on incremente par .num+1
 95	$sql = "SELECT count(*) as nb";
 96	$sql.= " FROM ".MAIN_DB_PREFIX."propal";
 97	$sql.= " WHERE ref LIKE '".$numpr."%'";
 98	$sql.= " AND entity = ".$conf->entity;
 99
100	$resql=$db->query($sql);
101	if ($resql)
102	{
103		$obj=$db->fetch_object($resql);
104		$num = $obj->nb;
105		$db->free($resql);
106		if ($num > 0)
107		{
108			$numpr .= "." . ($num + 1);
109		}
110	}
111
112	print '<form name="addprop" action="propal.php?socid='.$soc->id.'" method="POST">';
113	print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
114	print '<input type="hidden" name="action" value="add">';
115
116	if (isset($_GET["origin"]) && $_GET["origin"] != 'project' && isset($_GET["originid"]))
117	{
118		print '<input type="hidden" name="origin" value="'.$_GET["origin"].'">';
119		print '<input type="hidden" name="originid" value="'.$_GET["originid"].'">';
120	}
121
122	print '<table class="border" width="100%">';
123
124	// Ref
125	print '<tr><td class="fieldrequired">'.$langs->trans("Ref").'</td><td colspan="2"><input name="ref" value="'.$numpr.'"></td></tr>';
126
127	// Ref customer
128	print '<tr><td>'.$langs->trans('RefCustomer').'</td><td colspan="2">';
129	print '<input type="text" name="ref_client" value=""></td>';
130	print '</tr>';
131
132	// Third party
133	print '<tr><td class="fieldrequired">'.$langs->trans('Company').'</td><td colspan="2">'.$soc->getNomUrl(1);
134	print '<input type="hidden" name="socid" value="'.$soc->id.'">';
135	print '</td>';
136	print '</tr>';
137
138	// Contacts
139	print "<tr><td>".$langs->trans("DefaultContact")."</td><td colspan=\"2\">\n";
140	$form->select_contacts($soc->id,$setcontact,'contactidp',1);
141	print '</td></tr>';
142
143	// Ligne info remises tiers
144	print '<tr><td>'.$langs->trans('Discounts').'</td><td colspan="2">';
145	if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client);
146	else print $langs->trans("CompanyHasNoRelativeDiscount");
147	$absolute_discount=$soc->getAvailableDiscounts();
148	print '. ';
149	if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->trans("Currency".$conf->monnaie));
150	else print $langs->trans("CompanyHasNoAbsoluteDiscount");
151	print '.';
152	print '</td></tr>';
153
154	// Date
155	print '<tr><td class="fieldrequired">'.$langs->trans('Date').'</td><td colspan="2">';
156	$form->select_date('','','','','',"addprop");
157	print '</td></tr>';
158
159	// Validaty duration
160	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>';
161
162	// Terms of payment
163	print '<tr><td nowrap="nowrap" class="fieldrequired">'.$langs->trans('PaymentConditionsShort').'</td><td colspan="2">';
164	$form->select_conditions_paiements($soc->cond_reglement,'cond_reglement_id');
165	print '</td></tr>';
166
167	// Mode of payment
168	print '<tr><td>'.$langs->trans('PaymentMode').'</td><td colspan="2">';
169	$form->select_types_paiements($soc->mode_reglement,'mode_reglement_id');
170	print '</td></tr>';
171
172	// What trigger creation
173    print '<tr><td>'.$langs->trans('Source').'</td><td>';
174    $form->select_demand_reason($propal->demand_reason,'demand_reason_id',"SRC_PROP",1);
175    print '</td></tr>';
176
177	// Delivery delay
178    print '<tr><td>'.$langs->trans('AvailabilityPeriod').'</td><td colspan="2">';
179    $form->select_availability($propal->availability,'availability_id','',1);
180    print '</td></tr>';
181
182	// Delivery date (or manufacturing)
183	print '<tr><td>'.$langs->trans("DeliveryDate").'</td>';
184	print '<td colspan="2">';
185	if ($conf->global->DATE_LIVRAISON_WEEK_DELAY != "")
186	{
187		$tmpdte = time() + ((7 * $conf->global->DATE_LIVRAISON_WEEK_DELAY) * 24 * 60 * 60);
188		$syear = date("Y", $tmpdte);
189		$smonth = date("m", $tmpdte);
190		$sday = date("d", $tmpdte);
191		$form->select_date($syear."-".$smonth."-".$sday,'liv_','','','',"addprop");
192	}
193	else
194	{
195		$datepropal=empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0;
196		$form->select_date($datepropal,'liv_','','','',"addprop");
197	}
198	print '</td></tr>';
199
200	// Delivery address
201	if ($conf->global->PROPALE_ADD_DELIVERY_ADDRESS)
202	{
203		print '<tr><td>'.$langs->trans('DeliveryAddress').'</td>';
204		print '<td colspan="3">';
205		$numaddress = $form->select_address($soc->fk_delivery_address, $_GET['socid'],'fk_address',1);
206		if ($numaddress==0)
207		{
208			print ' &nbsp; <a href=../comm/address.php?socid='.$soc->id.'&action=create>'.$langs->trans("AddAddress").'</a>';
209		}
210		print '</td></tr>';
211	}
212
213	// Model
214	print '<tr>';
215	print '<td>'.$langs->trans("DefaultModel").'</td>';
216	print '<td colspan="2">';
217	$liste=ModelePDFPropales::liste_modeles($db);
218	print $form->selectarray('model',$liste,$conf->global->PROPALE_ADDON_PDF);
219	print "</td></tr>";
220
221	// Project
222	if ($conf->projet->enabled)
223	{
224		$projectid = 0;
225		if (isset($_GET["origin"]) && $_GET["origin"] == 'project') $projectid = ($_GET["originid"]?$_GET["originid"]:0);
226
227		print '<tr>';
228		print '<td valign="top">'.$langs->trans("Project").'</td><td colspan="2">';
229
230		$numprojet=select_projects($soc->id,$projectid);
231		if ($numprojet==0)
232		{
233			print ' &nbsp; <a href="../projet/fiche.php?socid='.$soc->id.'&action=create">'.$langs->trans("AddProject").'</a>';
234		}
235		print '</td>';
236		print '</tr>';
237	}
238
239	// Insert hooks
240	$parameters=array('socid'=>$socid);
241	$object=new Propal($db);
242	$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
243
244	print "</table>";
245	print '<br>';
246
247	/*
248	 * Combobox pour la fonction de copie
249	 */
250
251	if (empty($conf->global->PROPAL_CLONE_ON_CREATE_PAGE))
252	{
253		print '<input type="hidden" name="createmode" value="empty">';
254	}
255
256	print '<table>';
257	if (! empty($conf->global->PROPAL_CLONE_ON_CREATE_PAGE))
258	{
259		// For backward compatibility
260		print '<tr>';
261		print '<td><input type="radio" name="createmode" value="copy"></td>';
262		print '<td>'.$langs->trans("CopyPropalFrom").' </td>';
263		print '<td>';
264		$liste_propal = array();
265		$liste_propal[0] = '';
266
267		$sql ="SELECT p.rowid as id, p.ref, s.nom";
268		$sql.=" FROM ".MAIN_DB_PREFIX."propal p";
269		$sql.= ", ".MAIN_DB_PREFIX."societe s";
270		$sql.= " WHERE s.rowid = p.fk_soc";
271		$sql.= " AND p.entity = ".$conf->entity;
272		$sql.= " AND p.fk_statut <> 0";
273		$sql.= " ORDER BY Id";
274
275		$resql = $db->query($sql);
276		if ($resql)
277		{
278			$num = $db->num_rows($resql);
279			$i = 0;
280			while ($i < $num)
281			{
282				$row = $db->fetch_row($resql);
283				$propalRefAndSocName = $row[1]." - ".$row[2];
284				$liste_propal[$row[0]]=$propalRefAndSocName;
285				$i++;
286			}
287			print $form->selectarray("copie_propal",$liste_propal, 0);
288		}
289		else
290		{
291			dol_print_error($db);
292		}
293		print '</td></tr>';
294
295		if ($conf->global->PRODUCT_SHOW_WHEN_CREATE) print '<tr><td colspan="3">&nbsp;</td></tr>';
296
297		print '<tr><td valign="top"><input type="radio" name="createmode" value="empty" checked="checked"></td>';
298		print '<td valign="top" colspan="2">'.$langs->trans("CreateEmptyPropal").'</td></tr>';
299	}
300
301	if (! empty($conf->global->PRODUCT_SHOW_WHEN_CREATE))
302	{
303		print '<tr><td colspan="3">';
304		if ($conf->product->enabled || $conf->service->enabled)
305		{
306			$lib=$langs->trans("ProductsAndServices");
307
308			print '<table class="border" width="100%">';
309			print '<tr>';
310			print '<td>'.$lib.'</td>';
311			print '<td>'.$langs->trans("Qty").'</td>';
312			print '<td>'.$langs->trans("ReductionShort").'</td>';
313			print '</tr>';
314			for ($i = 1 ; $i <= $conf->global->PRODUCT_SHOW_WHEN_CREATE; $i++)
315			{
316				print '<tr><td>';
317				// multiprix
318				if($conf->global->PRODUIT_MULTIPRICES && $soc->price_level)
319				$form->select_produits('',"idprod".$i,'',$conf->product->limit_size,$soc->price_level);
320				else
321				$form->select_produits('',"idprod".$i,'',$conf->product->limit_size);
322				print '</td>';
323				print '<td><input type="text" size="2" name="qty'.$i.'" value="1"></td>';
324				print '<td><input type="text" size="2" name="remise'.$i.'" value="'.$soc->remise_client.'">%</td>';
325				print '</tr>';
326			}
327
328			print "</table>";
329
330		}
331		print '</td></tr>';
332	}
333	print '</table>';
334	print '<br>';
335
336	$langs->load("bills");
337	print '<center>';
338	print '<input type="submit" class="button" value="'.$langs->trans("CreateDraft").'">';
339	print '</center>';
340
341	print "</form>";
342}
343
344$db->close();
345
346llxFooter();
347?>