From ca90ebabe049571702af2da94db3ae892d2da345 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 29 Jan 2011 17:26:52 +0000 Subject: [PATCH] Fix: problem with price_min in mutli-price mode Fix: mutualize code Todo: code of contract card is obsolete --- htdocs/compta/facture.php | 2 +- htdocs/contrat/fiche.php | 227 ++++++++++++++++++-------------------- 2 files changed, 110 insertions(+), 119 deletions(-) diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 125a2901d4d..ccc19484906 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -54,7 +54,7 @@ $sall=isset($_GET['sall'])?trim($_GET['sall']):trim($_POST['sall']); $projectid=isset($_GET['projectid'])?$_GET['projectid']:0; // Security check -$socid=isset($_GET['socid'])?$_GET['socid']:$_POST['socid']; +$socid=GETPOST("socid"); $facid=GETPOST("id"); if (empty($facid)) $facid=GETPOST("facid"); // For backward compatibility $ref=GETPOST("ref"); diff --git a/htdocs/contrat/fiche.php b/htdocs/contrat/fiche.php index d456d29c585..ae5a29e6580 100644 --- a/htdocs/contrat/fiche.php +++ b/htdocs/contrat/fiche.php @@ -1,7 +1,7 @@ * Copyright (C) 2004-2009 Laurent Destailleur - * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2005-2011 Regis Houssin * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2010 Juanjo Menent * @@ -42,7 +42,7 @@ $langs->load("bills"); $langs->load("products"); // Security check -$socid=0; +$socid=GETPOST("socid"); $contratid = isset($_GET["id"])?$_GET["id"]:''; if ($user->societe_id) $socid=$user->societe_id; $result=restrictedArea($user,'contrat',$contratid,'contrat'); @@ -181,7 +181,7 @@ if ($_POST["action"] == 'classin') if ($_POST["action"] == 'addline' && $user->rights->contrat->creer) { - if ($_POST["pqty"] && (($_POST["pu"] != '' && $_POST["desc"]) || $_POST["p_idprod"])) + if ($_POST["pqty"] && (($_POST["pu"] != '' && $_POST["desc"]) || $_POST["idprod"])) { $contrat = new Contrat($db); $ret=$contrat->fetch($_GET["id"]); @@ -223,10 +223,10 @@ if ($_POST["action"] == 'addline' && $user->rights->contrat->creer) // Ecrase $desc par celui du produit // Ecrase $txtva par celui du produit // Ecrase $base_price_type par celui du produit - if ($_POST['p_idprod']) + if ($_POST['idprod']) { - $prod = new Product($db, $_POST['p_idprod']); - $prod->fetch($_POST['p_idprod']); + $prod = new Product($db, $_POST['idprod']); + $prod->fetch($_POST['idprod']); $tva_tx = get_default_tva($mysoc,$contrat->client,$prod->id); $tva_npr = get_default_npr($mysoc,$contrat->client,$prod->id); @@ -236,12 +236,14 @@ if ($_POST["action"] == 'addline' && $user->rights->contrat->creer) { $pu_ht = $prod->multiprices[$contrat->client->price_level]; $pu_ttc = $prod->multiprices_ttc[$contrat->client->price_level]; + $price_min = $prod->multiprices_min[$contrat->client->price_level]; $price_base_type = $prod->multiprices_base_type[$contrat->client->price_level]; } else { $pu_ht = $prod->price; $pu_ttc = $prod->price_ttc; + $price_min = $prod->price_min; $price_base_type = $prod->price_base_type; } @@ -277,23 +279,31 @@ if ($_POST["action"] == 'addline' && $user->rights->contrat->creer) $info_bits=0; if ($tva_npr) $info_bits |= 0x01; - - // Insert line - $result = $contrat->addline( - $desc, - $pu_ht, - $_POST["pqty"], - $tva_tx, - $localtax1_tx, - $localtax2_tx, - $_POST["p_idprod"], - $_POST["premise"], - $date_start, - $date_end, - $price_base_type, - $pu_ttc, - $info_bits - ); + + if($price_min && (price2num($pu_ht)*(1-price2num($_POST['remise_percent'])/100) < price2num($price_min))) + { + $contrat->error = $langs->trans("CantBeLessThanMinPrice",price2num($price_min,'MU').' '.$langs->trans("Currency".$conf->monnaie)) ; + $result = -1 ; + } + else + { + // Insert line + $result = $contrat->addline( + $desc, + $pu_ht, + $_POST["pqty"], + $tva_tx, + $localtax1_tx, + $localtax2_tx, + $_POST["idprod"], + $_POST["premise"], + $date_start, + $date_end, + $price_base_type, + $pu_ttc, + $info_bits + ); + } if ($result > 0) { @@ -344,6 +354,8 @@ if ($_POST["action"] == 'updateligne' && $user->rights->contrat->creer && ! $_PO $contratline->date_fin_validite=$date_end_update; $contratline->date_cloture=$date_end_real_update; $contratline->fk_user_cloture=$user->id; + + // TODO verifier price_min si fk_product et multiprix $result=$contratline->update($user); if ($result > 0) @@ -463,96 +475,80 @@ if ($_GET["action"] == 'create') dol_fiche_head($head, $a, $langs->trans("AddContract"), 0, 'contract'); if ($mesg) print $mesg; - - $new_contrat = new Contrat($db); - - $sql = "SELECT s.nom, s.prefix_comm, s.rowid"; - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; - $sql.= " WHERE s.rowid = ".$_GET["socid"]; - - $resql=$db->query($sql); - if ($resql) + + $soc = new Societe($db); + $soc->fetch($socid); + + print '
'; + print ''; + + print ''; + print ''."\n"; + print ''; + + print ''; + + // Ref + print ''; + print ''; + + // Customer + print ''; + + // Ligne info remises tiers + print ''; + + // Commercial suivi + print ''; + + // Commercial signature + print ''; + + print '"; + + if ($conf->projet->enabled) { - $num = $db->num_rows($resql); - if ($num) - { - $obj = $db->fetch_object($resql); - - $soc = new Societe($db); - $soc->fetch($obj->rowid); - - print ''; - print ''; - - print ''; - print ''."\n"; - print ''; - - print '
'.$langs->trans("Ref").'
'.$langs->trans("Customer").''.$soc->getNomUrl(1).'
'.$langs->trans('Discount').''; + if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client); + else print $langs->trans("CompanyHasNoRelativeDiscount"); + $absolute_discount=$soc->getAvailableDiscounts(); + print '. '; + if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->trans("Currency".$conf->monnaie)); + else print $langs->trans("CompanyHasNoAbsoluteDiscount"); + print '.'; + print '
'.$langs->trans("TypeContact_contrat_internal_SALESREPFOLL").''; + print $form->select_users(GETPOST("commercial_suivi_id"),'commercial_suivi_id',1,''); + print '
'.$langs->trans("TypeContact_contrat_internal_SALESREPSIGN").''; + print $form->select_users(GETPOST("commercial_signature_id"),'commercial_signature_id',1,''); + print '
'.$langs->trans("Date").''; + $form->select_date($datecontrat,'',0,0,'',"contrat"); + print "
'; - - // Ref - print ''; - print ''; - - // Customer - print ''; - - // Ligne info remises tiers - print ''; - - // Commercial suivi - print ''; - - // Commercial signature - print ''; - - print '"; - - if ($conf->projet->enabled) - { - print '"; - } - - print ''; - - if (! $user->societe_id) - { - print ''; - } - - print ''; - - print "
'.$langs->trans("Ref").'
'.$langs->trans("Customer").''.$soc->getNomUrl(1).'
'.$langs->trans('Discount').''; - if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client); - else print $langs->trans("CompanyHasNoRelativeDiscount"); - $absolute_discount=$soc->getAvailableDiscounts(); - print '. '; - if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->trans("Currency".$conf->monnaie)); - else print $langs->trans("CompanyHasNoAbsoluteDiscount"); - print '.'; - print '
'.$langs->trans("TypeContact_contrat_internal_SALESREPFOLL").''; - print $form->select_users($_REQUEST["commercial_suivi_id"],'commercial_suivi_id',1,''); - print '
'.$langs->trans("TypeContact_contrat_internal_SALESREPSIGN").''; - print $form->select_users($_REQUEST["commercial_signature_id"],'commercial_signature_id',1,''); - print '
'.$langs->trans("Date").''; - $form->select_date($datecontrat,'',0,0,'',"contrat"); - print "
'.$langs->trans("Project").''; - select_projects($soc->id,$_REQUEST["projectid"],"projectid"); - print "
'.$langs->trans("NotePublic").''; - print '
'.$langs->trans("NotePrivate").''; - print '
\n"; - - print "
\n"; + print ''.$langs->trans("Project").''; + select_projects($soc->id,GETPOST("projectid"),"projectid"); + print ""; + } + + print ''.$langs->trans("NotePublic").''; + print ''; + + if (! $user->societe_id) + { + print ''.$langs->trans("NotePrivate").''; + print ''; + } + + print ''; + + print "\n"; + print "\n"; +// TODO A quoi ca sert ? +/* if ($propalid) { - /* - * Produits - */ print '
'; print_titre($langs->trans("Products")); @@ -618,12 +614,7 @@ if ($_GET["action"] == 'create') print ''; } - } - } - else - { - dol_print_error($db); - } +*/ print ''; } @@ -634,7 +625,7 @@ else /* */ /* *************************************************************************** */ { - $now=gmmktime(); + $now=dol_now(); $id = $_GET["id"]; $ref= $_GET['ref']; @@ -1225,9 +1216,9 @@ else print ''; // multiprix if($conf->global->PRODUIT_MULTIPRICES) - $form->select_produits('','p_idprod',1,$conf->product->limit_size,$contrat->societe->price_level); + $form->select_produits('','idprod',1,$conf->product->limit_size,$contrat->societe->price_level); else - $form->select_produits('','p_idprod',1,$conf->product->limit_size); + $form->select_produits('','idprod',1,$conf->product->limit_size); if (! $conf->global->PRODUIT_USE_SEARCH_TO_SELECT) print '
'; print ''; print '';