diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 11412c01793..ffa22983385 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -425,12 +425,19 @@ if ($_GET['action'] == 'modif' && $user->rights->propale->creer) if ($_POST['action'] == "setabsolutediscount" && $user->rights->propale->creer) { - $propal = new Propal($db); - $ret=$propal->fetch($_POST['propalid']); - if ($_POST["remise_id"]) { - $propal->insert_discount($_POST["remise_id"]); + $propal = new Propal($db); + $propal->id=$_GET['propalid']; + $ret=$propal->fetch($_GET['propalid']); + if ($ret > 0) + { + $propal->insert_discount($_POST["remise_id"]); + } + else + { + dolibarr_print_error($db,$propal->error); + } } } @@ -737,9 +744,9 @@ if ($_GET['propalid'] > 0) print '. '; if ($absolute_discount) { - print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie)); - print '.'; -// print $html->form_remise_dispo($_SERVER["PHP_SELF"].'?propalid='.$propal->id,0,'remise_id',$societe->id); + print '
'; + //print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie)); + print $html->form_remise_dispo($_SERVER["PHP_SELF"].'?propalid='.$propal->id,0,'remise_id',$societe->id,$absolute_discount); } else print $langs->trans("CompanyHasNoAbsoluteDiscount").'.'; print ''; @@ -878,28 +885,6 @@ if ($_GET['propalid'] > 0) } print ''; - // Destinataire -/* On gère les contacts sur onglet contact - $langs->load('mails'); - print ''; - print ''; - if ($_GET['action'] != 'editcontact' && $propal->brouillon) print ''; - print '
'; - print $langs->trans('MailTo'); - print 'id.'">'.img_edit($langs->trans('SetReceiver'),1).'
'; - print ''; - if ($_GET['action'] == 'editcontact') - { - $html->form_contacts($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$societe,$propal->contactid,'contactidp'); - } - else - { - $html->form_contacts($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$societe,$propal->contactid,'none'); - } - print ''; - print ''; -*/ - // Projet if ($conf->projet->enabled) { @@ -974,7 +959,8 @@ if ($_GET['propalid'] > 0) */ print ''; - $sql = 'SELECT pt.rowid, pt.description, pt.price, pt.fk_product, pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice,'; + $sql = 'SELECT pt.rowid, pt.description, pt.price, pt.fk_product, pt.fk_remise_except,'; + $sql.= ' pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice, pt.info_bits,'; $sql.= ' p.label as product, p.ref, p.fk_product_type, p.rowid as prodid,'; $sql.= ' p.description as product_desc'; $sql.= ' FROM '.MAIN_DB_PREFIX.'propaldet as pt'; @@ -1013,7 +999,8 @@ if ($_GET['propalid'] > 0) print ''; if ($objp->fk_product > 0) { - print '
'; + print ''; + print ''; if ($objp->fk_product_type) print img_object($langs->trans('ShowService'),'service'); else print img_object($langs->trans('ShowProduct'),'product'); print ' '.$objp->ref.''; @@ -1041,7 +1028,18 @@ if ($_GET['propalid'] > 0) } else { - print ''.stripslashes(nl2br($objp->description)); + print ''; + if ($objp->info_bits == 2) + { + print ''; + print $langs->trans("Discount"); + print ''; + if ($objp->description) print ': '.nl2br($objp->description); + } + else + { + print nl2br($objp->description); + } if ($objp->date_start && $objp->date_end) { print ' (Du '.dolibarr_print_date($objp->date_start).' au '.dolibarr_print_date($objp->date_end).')'; diff --git a/htdocs/compta/propal.php b/htdocs/compta/propal.php index 9c8e93e47c4..c2f744a2d47 100644 --- a/htdocs/compta/propal.php +++ b/htdocs/compta/propal.php @@ -544,16 +544,16 @@ et non globalement /* * Boutons Actions */ - if ($obj->statut <> 4 && $user->societe_id == 0) + if ($propal->statut <> 4 && $user->societe_id == 0) { print '
'; - - if ($obj->statut == 2 && $user->rights->facture->creer) + + if ($propal->statut == 2 && $user->rights->facture->creer) { print '".$langs->trans("BuildBill").""; } - if ($obj->statut == 2 && sizeof($propal->getFactureListeArray())) + if ($propal->statut == 2 && sizeof($propal->getFactureListeArray())) { print '".$langs->trans("ClassifyBilled").""; } diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index 7814b3e4293..74120d37a9d 100644 --- a/htdocs/facture.class.php +++ b/htdocs/facture.class.php @@ -2206,7 +2206,7 @@ class FactureLigne $sql.= " '".price2num($this->qty)."',"; $sql.= " '".price2num($this->txtva)."',"; if ($this->fk_product) { $sql.= "'".$this->fk_product."',"; } - else { $sql.='0,'; } + else { $sql.='null,'; } $sql.= " '".price2num($this->remise_percent)."',"; $sql.= " '".price2num($this->subprice)."',"; $sql.= " '".price2num($this->remise)."',"; diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php index 81a4fb51953..92ae94b5f99 100644 --- a/htdocs/html.form.class.php +++ b/htdocs/html.form.class.php @@ -1670,16 +1670,17 @@ class Form * \param selected Valeur à appliquer * \param htmlname Nom du formulaire select. Si none, non modifiable */ - function form_remise_dispo($page, $selected='', $htmlname='remise_id',$socid) + function form_remise_dispo($page, $selected='', $htmlname='remise_id',$socid, $absolute_discount) { - global $langs; + global $conf,$langs; if ($htmlname != "none") { print '
'; print ''; print ''; print ''; print ''; diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index a3527a762dc..da4b2543462 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -198,6 +198,7 @@ LawApplicationPart3=vendeur jusqu' LawApplicationPart4=leurs prix. VATDischarged=TVA acquittée sur les débits. LimitedLiabilityCompanyCapital=SARL au Capital de +UseDiscount=Use discount # oursin PDF model Of=du diff --git a/htdocs/langs/en_US/companies.lang b/htdocs/langs/en_US/companies.lang index 0000a39426f..6d4e6370d75 100644 --- a/htdocs/langs/en_US/companies.lang +++ b/htdocs/langs/en_US/companies.lang @@ -80,9 +80,9 @@ CustomerRelativeDiscount=Relative customer discount CustomerAbsoluteDiscount=Absolute customer discount CustomerRelativeDiscountShort=Relative discount CustomerAbsoluteDiscountShort=Absolute discount -CompanyHasRelativeDiscount=This customer has a discount of %s%% -CompanyHasNoRelativeDiscount=This customer has no discount by default -CompanyHasAbsoluteDiscount=This customer has a %s %s discount credit +CompanyHasRelativeDiscount=This customer has a discount of %s%% +CompanyHasNoRelativeDiscount=This customer has no relative discount by default +CompanyHasAbsoluteDiscount=This customer has a %s %s discount credit CompanyHasNoAbsoluteDiscount=This customer has no discount credit available CustomerAbsoluteDiscountAllUsers=Absolute discounts (granted by all users) CustomerAbsoluteDiscountMy=Absolute discounts (granted by yourself) diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index 094a25cc04c..cd7e7d3907e 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -82,7 +82,7 @@ PriceRemoved=Price removed BarCode=Barcode NoteNotVisibleOnBill=Note (not visible on invoices, proposals...) CreateCopy=Create copy -ServiceLimitedDuration=If produced of service type at limited duration: +ServiceLimitedDuration=If product is a service with limited duration: MultiPricesAbility=Activate the multi-prices MultiPricesNumPrices=Number of price MultiPriceLevelsName=Price categories diff --git a/htdocs/langs/fr_FR/bills.lang b/htdocs/langs/fr_FR/bills.lang index 89fabb32421..52d9f2e3c02 100644 --- a/htdocs/langs/fr_FR/bills.lang +++ b/htdocs/langs/fr_FR/bills.lang @@ -198,6 +198,7 @@ LawApplicationPart3=vendeur jusqu' LawApplicationPart4=leurs prix. VATDischarged=TVA acquittée sur les débits. LimitedLiabilityCompanyCapital=SARL au Capital de +UseDiscount=Appliquer remise # oursin PDF model Of=du diff --git a/htdocs/langs/fr_FR/companies.lang b/htdocs/langs/fr_FR/companies.lang index d5b1433218f..501bd5b4e92 100644 --- a/htdocs/langs/fr_FR/companies.lang +++ b/htdocs/langs/fr_FR/companies.lang @@ -80,9 +80,9 @@ CustomerRelativeDiscount=Remise client relative CustomerAbsoluteDiscount=Remise client fixe CustomerRelativeDiscountShort=Remise relative CustomerAbsoluteDiscountShort=Remise fixe -CompanyHasRelativeDiscount=Ce client a une remise par défaut de %s%% -CompanyHasNoRelativeDiscount=Ce client n'a pas de remises par défaut -CompanyHasAbsoluteDiscount=Ce client a %s %s de remises fixes disponibles +CompanyHasRelativeDiscount=Ce client a une remise par défaut de %s%% +CompanyHasNoRelativeDiscount=Ce client n'a pas de remises relatives par défaut +CompanyHasAbsoluteDiscount=Ce client a %s %s de remises fixes disponibles CompanyHasNoAbsoluteDiscount=Ce client n'a pas ou plus de remises fixes disponibles CustomerAbsoluteDiscountAllUsers=Remises fixes en cours (accordées par tout utilisateur) CustomerAbsoluteDiscountMy=Remises fixes en cours (accordées personnellement) diff --git a/htdocs/propal.class.php b/htdocs/propal.class.php index b7f4a6f8ef1..224b5c7ff81 100644 --- a/htdocs/propal.class.php +++ b/htdocs/propal.class.php @@ -155,10 +155,66 @@ class Propal extends CommonObject * \return int >0 si ok, <0 si ko * \see add_product */ - function insert_discount($idproduct, $qty, $remise_percent=0, $desc='') + function insert_discount($idremise) { + global $langs; + include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php'); + include_once(DOL_DOCUMENT_ROOT.'/discount.class.php'); + $this->db->begin(); + + $remise=new DiscountAbsolute($this->db); + $result=$remise->fetch($idremise); + + if ($result > 0) + { + $propalligne=new PropaleLigne($this->db); + $propalligne->fk_propal=$this->id; + $propalligne->fk_remise_except=$remise->id; + $propalligne->desc=$remise->description; // Description ligne + $propalligne->tva_tx=$remise->tva_tx; + $propalligne->subprice=-$remise->amount_ht; + $propalligne->price=-$remise->amount_ht; + $propalligne->fk_product=0; // Id produit prédéfini + $propalligne->qty=1; + $propalligne->remise=0; + $propalligne->remise_percent=0; + $propalligne->rang=-1; + $propalligne->info_bits=2; + + $tabprice=calcul_price_total($propalligne->qty, $propalligne->subprice, 0,$propalligne->tva_tx); + $propalligne->total_ht = $tabprice[0]; + $propalligne->total_tva = $tabprice[1]; + $propalligne->total_ttc = $tabprice[2]; + + $result=$propalligne->insert(); + if ($result > 0) + { + $result=$this->update_price(); + if ($result > 0) + { + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + return -1; + } + } + else + { + $this->error=$propalligne->error; + $this->db->rollback(); + return -2; + } + } + else + { + $this->db->rollback(); + return -2; + } } /** @@ -211,22 +267,6 @@ class Propal extends CommonObject $price = $pu - $remise; } - // Récupère rang max de la propale dans $rangmax - $sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.'propaldet'; - $sql.= ' WHERE fk_propal ='.$propalid; - $resql = $this->db->query($sql); - if ($resql) - { - $row = $this->db->fetch_row($resql); - $rangmax = $row[0]; - } - else - { - dolibarr_print_error($this->db); - $this->db->rollback(); - return -1; - } - // Insertion ligne $ligne=new PropaleLigne($this->db); @@ -239,7 +279,7 @@ class Propal extends CommonObject $ligne->remise_percent=$remise_percent; $ligne->subprice=$subprice; $ligne->remise=$remise; - $ligne->rang=($rangmax+1); + $ligne->rang=-1; $ligne->info_bits=$info_bits; $ligne->total_ht=$total_ht; $ligne->total_tva=$total_tva; @@ -553,25 +593,12 @@ class Propal extends CommonObject // Anciens indicateurs $this->amount_ht += $obj->price * $obj->qty; $this->total_remise += 0; // Plus de remise globale (toute remise est sur une ligne) -/* \deprecated car simplifie par les 3 indicateurs total_ht, total_tva et total_ttc sur lignes - $products[$i][0] = $obj->price; - $products[$i][1] = $obj->qty; - $products[$i][2] = $obj->tva_tx; -*/ $i++; } $this->db->free($result); } -/* \deprecated car simplifie par les 3 indicateurs total_ht, total_tva et total_ttc sur lignes - $calculs = calcul_price($products, $this->remise_percent, $this->remise_absolue); - $this->total_remise = $calculs[3]; - $this->amount_ht = $calculs[4]; - $this->total_ht = $calculs[0]; - $this->total_tva = $calculs[1]; - $this->total_ttc = $calculs[2]; - $tvas = $calculs[5]; -*/ + // Met a jour en base $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET"; $sql .= " price='". price2num($this->total_ht)."'"; @@ -592,7 +619,7 @@ class Propal extends CommonObject } - /** + /** * \brief Stocke un numéro de rang pour toutes les lignes de * detail d'une propale qui n'en ont pas. */ @@ -876,6 +903,8 @@ class Propal extends CommonObject return 1; } + + $this->error="Record Not Found"; return 0; } else @@ -2069,6 +2098,7 @@ class PropaleLigne var $coef; var $info_bits; // Bit 0: 0 si TVA normal - 1 si TVA NPR + // Bit 1: 0 ligne normale - 1 si ligne de remise fixe var $total_ht; // Total HT de la ligne toute quantité et incluant la remise ligne var $total_tva; // Total TVA de la ligne toute quantité et incluant la remise ligne var $total_ttc; // Total TTC de la ligne toute quantité et incluant la remise ligne @@ -2141,8 +2171,29 @@ class PropaleLigne */ function insert() { + dolibarr_syslog("PropaleLigne::insert rang=".$this->rang); $this->db->begin(); + $rangtouse=$this->rang; + if ($rangtouse == -1) + { + // Récupère rang max de la propale dans $rangmax + $sql = 'SELECT max(rang) as max FROM '.MAIN_DB_PREFIX.'propaldet'; + $sql.= ' WHERE fk_propal ='.$this->fk_propal; + $resql = $this->db->query($sql); + if ($resql) + { + $obj = $this->db->fetch_object($resql); + $rangtouse = $obj->max + 1; + } + else + { + dolibarr_print_error($this->db); + $this->db->rollback(); + return -1; + } + } + // Insertion dans base de la ligne $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'propaldet'; $sql.= ' (fk_propal, description, price, qty, tva_tx,'; @@ -2155,13 +2206,13 @@ class PropaleLigne $sql.= " '".price2num($this->qty)."',"; $sql.= " '".price2num($this->tva_tx)."',"; if ($this->fk_product) { $sql.= "'".$this->fk_product."',"; } - else { $sql.='0,'; } + else { $sql.='null,'; } $sql.= " '".price2num($this->remise_percent)."',"; $sql.= " '".price2num($this->subprice)."',"; $sql.= " '".price2num($this->remise)."',"; if ($this->fk_remise_except) $sql.= $this->fk_remise_except.","; else $sql.= 'null,'; - $sql.= ' '.$this->rang.','; + $sql.= ' '.$rangtouse.','; if (isset($this->coef)) $sql.= ' '.$this->coef.','; else $sql.= ' null,'; $sql.= " '".$this->info_bits."',"; @@ -2175,15 +2226,16 @@ class PropaleLigne $resql=$this->db->query($sql); if ($resql) { + $this->rang=$rangmax; $this->db->commit(); return 1; } else { - $this->error=$this->db->error(); + $this->error=$this->db->error()." sql=".$sql; dolibarr_syslog("PropaleLigne::insert Error ".$this->error); $this->db->rollback(); - return -2; + return -1; } }
'; - print $langs->trans("AvailableGlobalDiscounts").': '; + print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie)).': '; +// print $langs->trans("AvailableGlobalDiscounts").': '; print $this->select_remises('',$htmlname,'fk_facture IS NULL',$socid); print '