diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index ffa22983385..ccc7449bd9a 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -171,28 +171,31 @@ if ($_POST['action'] == 'add') // Si on a selectionné une propal à copier, on réalise la copie if($_POST['createmode']=='copy' && $_POST['copie_propal']) { - if ($propal->load_from($_POST['copie_propal']) == -1) + if ($propal->fetch($_POST['copie_propal']) > 0) + { + $propal->datep = mktime(12, 1, 1, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); + $propal->date_livraison = mktime(12, 1, 1, $_POST['liv_month']."-".$_POST['liv_day']."-".$_POST['liv_year']); + $propal->adresse_livraison_id = $_POST['adresse_livraison_id']; + $propal->duree_validite = $_POST['duree_validite']; + $propal->cond_reglement_id = $_POST['cond_reglement_id']; + $propal->mode_reglement_id = $_POST['mode_reglement_id']; + $propal->remise_percent = $_POST['remise_percent']; + $propal->remise_absolue = $_POST['remise_absolue']; + $propal->socidp = $_POST['socidp']; + $propal->contactid = $_POST['contactidp']; + $propal->projetidp = $_POST['projetidp']; + $propal->modelpdf = $_POST['modelpdf']; + $propal->author = $user->id; + $propal->note = $_POST['note']; + $propal->ref = $_POST['ref']; + $propal->statut = 0; + + $id = $propal->create_from(); + } + else { $msg = '
'.$langs->trans("ErrorFailedToCopyProposal",$_POST['copie_propal']).'
'; } - $propal->datep = mktime(12, 1, 1, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); - $propal->date_livraison = mktime(12, 1, 1, $_POST['liv_month']."-".$_POST['liv_day']."-".$_POST['liv_year']); - $propal->adresse_livraison_id = $_POST['adresse_livraison_id']; - $propal->duree_validite = $_POST['duree_validite']; - $propal->cond_reglement_id = $_POST['cond_reglement_id']; - $propal->mode_reglement_id = $_POST['mode_reglement_id']; - $propal->remise_percent = $_POST['remise_percent']; - $propal->remise_absolue = $_POST['remise_absolue']; - $propal->socidp = $_POST['socidp']; - $propal->contactid = $_POST['contactidp']; - $propal->projetidp = $_POST['projetidp']; - $propal->modelpdf = $_POST['modelpdf']; - $propal->author = $user->id; - $propal->note = $_POST['note']; - $propal->ref = $_POST['ref']; - $propal->statut = 0; - - $id = $propal->create_from(); } else { @@ -641,7 +644,7 @@ if ($_GET['action'] == 'down' && $user->rights->propale->creer) -llxHeader(); +llxHeader('',$langs->trans('Proposal'),'Proposition'); $html = new Form($db); @@ -744,9 +747,15 @@ if ($_GET['propalid'] > 0) print '. '; if ($absolute_discount) { - 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); + if ($propal->statut > 0) + { + print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie)); + } + else + { + print '
'; + print $html->form_remise_dispo($_SERVER["PHP_SELF"].'?propalid='.$propal->id,0,'remise_id',$societe->id,$absolute_discount); + } } else print $langs->trans("CompanyHasNoAbsoluteDiscount").'.'; print ''; @@ -1004,11 +1013,10 @@ if ($_GET['propalid'] > 0) if ($objp->fk_product_type) print img_object($langs->trans('ShowService'),'service'); else print img_object($langs->trans('ShowProduct'),'product'); print ' '.$objp->ref.''; - print ' - '.nl2br(stripslashes($objp->product)); - + print ' - '.nl2br($objp->product); if ($conf->global->PROP_ADD_PROD_DESC && !$conf->global->PRODUIT_CHANGE_PROD_DESC) { - print '
'.nl2br(stripslashes($objp->product_desc)); + print '
'.nl2br($objp->product_desc); } if ($objp->date_start && $objp->date_end) @@ -1029,34 +1037,40 @@ if ($_GET['propalid'] > 0) else { print ''; - if ($objp->info_bits == 2) + if (($objp->info_bits & 2) == 2) { print ''; - print $langs->trans("Discount"); + print img_object($langs->trans("ShowReduc"),'reduc').' '.$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).')'; - } - if ($objp->date_start && ! $objp->date_end) - { - print ' (A partir du '.dolibarr_print_date($objp->date_start).')'; - } - if (! $objp->date_start && $objp->date_end) - { - print " (Jusqu'au ".dolibarr_print_date($objp->date_end).')'; + if ($objp->date_start && $objp->date_end) + { + print ' (Du '.dolibarr_print_date($objp->date_start).' au '.dolibarr_print_date($objp->date_end).')'; + } + if ($objp->date_start && ! $objp->date_end) + { + print ' (A partir du '.dolibarr_print_date($objp->date_start).')'; + } + if (! $objp->date_start && $objp->date_end) + { + print " (Jusqu'au ".dolibarr_print_date($objp->date_end).')'; + } } print "\n"; } print ''.$objp->tva_tx.'%'; print ''.price($objp->subprice)."\n"; - print ''.$objp->qty.''; + print ''; + if (($objp->info_bits & 2) != 2) + { + print $objp->qty; + } + else print ' '; + print ''; if ($objp->remise_percent > 0) { print ''.$objp->remise_percent."%\n"; @@ -1121,19 +1135,31 @@ if ($_GET['propalid'] > 0) if ($objp->fk_product_type) print img_object($langs->trans('ShowService'),'service'); else print img_object($langs->trans('ShowProduct'),'product'); print ' '.$objp->ref.''; - print ' - '.stripslashes(nl2br($objp->product)); + print ' - '.nl2br($objp->product); print '
'; } - print ''; + print ''; print ''; if($societe->tva_assuj == "0") print '0'; else print $html->select_tva("tva_tx",$objp->tva_tx,$mysoc,$societe); print ''; - print ''; - print ''; - print '%'; + print ''; + print ''; + if (($objp->info_bits & 2) != 2) + { + print ''; + } + else print ' '; + print ''; + print ''; + if (($objp->info_bits & 2) != 2) + { + print '%'; + } + else print ' '; + print ''; print ''; print '
'; print '' . "\n"; @@ -1436,7 +1462,7 @@ if ($_GET['propalid'] > 0) $file = $conf->propal->dir_output . '/'.$propref.'/'.$propref.'.pdf'; if (file_exists($file)) { - print ''.$langs->trans('Send').''; + print ''.$langs->trans('SendByMail').''; } } } diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php index 9f4b385c8d7..d3b9d7ca35e 100644 --- a/htdocs/commande/commande.class.php +++ b/htdocs/commande/commande.class.php @@ -516,22 +516,6 @@ class Commande extends CommonObject $price = $pu - $remise; } - // Récupère rang max de la commande dans $rangmax - $sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.'commandedet'; - $sql.= ' WHERE fk_commande ='.$commandeid; - $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 CommandeLigne($this->db); @@ -545,7 +529,7 @@ class Commande 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; @@ -882,6 +866,73 @@ class Commande extends CommonObject } + /** + * \brief Ajout d'une ligne remise fixe dans la commande, en base + * \param idremise Id de la remise fixe + * \return int >0 si ok, <0 si ko + */ + 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) + { + $comligne=new CommandeLigne($this->db); + $comligne->fk_commande=$this->id; + $comligne->fk_remise_except=$remise->id; + $comligne->desc=$remise->description; // Description ligne + $comligne->tva_tx=$remise->tva_tx; + $comligne->subprice=-$remise->amount_ht; + $comligne->price=-$remise->amount_ht; + $comligne->fk_product=0; // Id produit prédéfini + $comligne->qty=1; + $comligne->remise=0; + $comligne->remise_percent=0; + $comligne->rang=-1; + $comligne->info_bits=2; + + $tabprice=calcul_price_total($comligne->qty, $comligne->subprice, 0,$comligne->tva_tx); + $comligne->total_ht = $tabprice[0]; + $comligne->total_tva = $tabprice[1]; + $comligne->total_ttc = $tabprice[2]; + + $result=$comligne->insert(); + if ($result > 0) + { + $result=$this->update_price($this->id); + if ($result > 0) + { + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + return -1; + } + } + else + { + $this->error=$comligne->error; + $this->db->rollback(); + return -2; + } + } + else + { + $this->db->rollback(); + return -2; + } + } + /* * * @@ -2027,8 +2078,29 @@ class CommandeLigne */ function insert() { + dolibarr_syslog("CommandeLigne.class::insert rang=".$this->rang); $this->db->begin(); + $rangtouse=$this->rang; + if ($rangtouse == -1) + { + // Récupère rang max de la commande dans $rangmax + $sql = 'SELECT max(rang) as max FROM '.MAIN_DB_PREFIX.'commandedet'; + $sql.= ' WHERE fk_commande ='.$this->fk_commande; + $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.'commandedet'; $sql.= ' (fk_commande, label, description, price, qty, tva_tx,'; @@ -2048,7 +2120,7 @@ class CommandeLigne $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."',"; diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index b05e76dec22..6824efce96d 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -105,7 +105,7 @@ if ($_POST['action'] == 'add' && $user->rights->commande->creer) $commande->contactid = $_POST['contactidp']; $commande->fetch_client(); - + $commande->add_product($_POST['idprod1'],$_POST['qty1'],$_POST['remise_percent1']); $commande->add_product($_POST['idprod2'],$_POST['qty2'],$_POST['remise_percent2']); $commande->add_product($_POST['idprod3'],$_POST['qty3'],$_POST['remise_percent3']); @@ -161,6 +161,24 @@ if ($_POST['action'] == 'setremise' && $user->rights->commande->creer) $commande->set_remise($user, $_POST['remise']); } +if ($_POST['action'] == "setabsolutediscount" && $user->rights->propale->creer) +{ + if ($_POST["remise_id"]) + { + $com = new Commande($db); + $com->id=$_GET['id']; + $ret=$com->fetch($_GET['id']); + if ($ret > 0) + { + $com->insert_discount($_POST["remise_id"]); + } + else + { + dolibarr_print_error($db,$com->error); + } + } +} + if ($_POST['action'] == 'setdate_livraison' && $user->rights->commande->creer) { $datelivraison=@mktime(0, 0, 0, $_POST['liv_month'], $_POST['liv_day'], $_POST['liv_year']); @@ -223,7 +241,7 @@ if ($_POST['action'] == 'addligne' && $user->rights->commande->creer) $ret=$commande->fetch($_POST['id']); $soc = new Societe($db, $commande->socidp); $soc->fetch($commande->socidp); - + if ($ret < 0) { dolibarr_print_error($db,$commande->error); @@ -237,9 +255,9 @@ if ($_POST['action'] == 'addligne' && $user->rights->commande->creer) { $prod = new Product($db, $_POST['idprod']); $prod->fetch($_POST['idprod']); - + $libelle = $prod->libelle; - + // multiprix if ($conf->global->PRODUIT_MULTIPRICES == 1) { @@ -249,7 +267,7 @@ if ($_POST['action'] == 'addligne' && $user->rights->commande->creer) { $pu=$prod->price; } - + // La description de la ligne est celle saisie ou // celle du produit si (non saisi + PRODUIT_CHANGE_PROD_DESC défini) $desc=$_POST['np_desc']; @@ -257,7 +275,7 @@ if ($_POST['action'] == 'addligne' && $user->rights->commande->creer) { $desc = $prod->description; } - + $tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx); } else @@ -266,7 +284,7 @@ if ($_POST['action'] == 'addligne' && $user->rights->commande->creer) $tva_tx=$_POST['tva_tx']; $desc=$_POST['desc']; } - + $commande->addline( $_POST['id'], $libelle, @@ -317,7 +335,7 @@ if ($_POST['action'] == 'updateligne' && $user->rights->commande->creer && $_POS dolibarr_print_error($db,$commande->error); exit; } - + $_GET['id']=$_POST['id']; // Pour réaffichage de la fiche en cours d'édition } @@ -395,7 +413,7 @@ if ($_POST['action'] == 'confirm_deleteproductline' && $_POST['confirm'] == 'yes exit; } -if ($_GET['action'] == 'modif' && $user->rights->commande->creer) +if ($_GET['action'] == 'modif' && $user->rights->commande->creer) { /* * Repasse la commande en mode brouillon @@ -446,7 +464,7 @@ if ($_REQUEST['action'] == 'builddoc') // En get ou en post { dolibarr_print_error($db,$result); exit; - } + } } // Efface les fichiers @@ -497,25 +515,25 @@ if ($_POST['action'] == 'send') $message = $_POST['message']; $sendtocc = $_POST['sendtocc']; $deliveryreceipt = $_POST['deliveryreceipt']; - + if ($_POST['action'] == 'send') { $subject = $_POST['subject']; - + if($subject == '') { $subject = $langs->trans('Order').' '.$commande->ref; } - + $actiontypeid=8; $actionmsg ='Mail envoyé par '.$from.' à '.$sendto.'.
'; - + if ($message) { $actionmsg.='Texte utilisé dans le corps du message:
'; $actionmsg.=$message; } - + $actionmsg2='Envoi commande par mail'; } @@ -580,7 +598,7 @@ if ($_POST['action'] == 'send') } -llxHeader('',$langs->trans('OrderCard'),'Commande'); +llxHeader('',$langs->trans('Order'),'Commande'); $html = new Form($db); @@ -663,7 +681,7 @@ if ($_GET['action'] == 'create' && $user->rights->commande->creer) else print $langs->trans("CompanyHasNoAbsoluteDiscount"); print '.'; print ''; - + // Date print ''.$langs->trans('Date').''; $html->select_date('','re','','','',"crea_commande"); @@ -948,7 +966,7 @@ else $html->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('Cancel'), $langs->trans('ConfirmCancelOrder'), 'confirm_cancel'); print '
'; } - + /* * Confirmation de la suppression d'une ligne produit */ @@ -1001,14 +1019,24 @@ else print ''; // Ligne info remises tiers - print ''.$langs->trans('Discounts').''; + print ''.$langs->trans('Discounts').''; if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client); else print $langs->trans("CompanyHasNoRelativeDiscount"); $absolute_discount=$soc->getCurrentDiscount(); print '. '; - if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie)); - else print $langs->trans("CompanyHasNoAbsoluteDiscount"); - print '.'; + if ($absolute_discount) + { + if ($commande->statut > 0) + { + print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie)); + } + else + { + print '
'; + print $html->form_remise_dispo($_SERVER["PHP_SELF"].'?id='.$commande->id,0,'remise_id',$soc->id,$absolute_discount); + } + } + else print $langs->trans("CompanyHasNoAbsoluteDiscount").'.'; print ''; // Date @@ -1133,16 +1161,16 @@ else // Lignes de 3 colonnes // Total HT - print ''.$langs->trans('TotalHT').''; + print ''.$langs->trans('AmountHT').''; print ''.price($commande->total_ht).''; print ''.$langs->trans('Currency'.$conf->monnaie).''; // Total TVA - print ''.$langs->trans('TotalVAT').''.price($commande->total_tva).''; + print ''.$langs->trans('AmountVAT').''.price($commande->total_tva).''; print ''.$langs->trans('Currency'.$conf->monnaie).''; // Total TTC - print ''.$langs->trans('TotalTTC').''.price($commande->total_ttc).''; + print ''.$langs->trans('AmountTTC').''.price($commande->total_ttc).''; print ''.$langs->trans('Currency'.$conf->monnaie).''; // Statut @@ -1154,16 +1182,11 @@ else print "\n"; /* - * Lignes de commandes - */ - $sql = 'SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice,'; - $sql.= ' p.label as product, p.ref, p.fk_product_type, p.rowid as prodid'; - - if ($conf->global->COM_ADD_PROD_DESC && !$conf->global->PRODUIT_CHANGE_PROD_DESC) - { - $sql.= ', p.description as product_desc'; - } - + * Lignes de commandes + */ + $sql = 'SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice, l.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.'commandedet as l'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product=p.rowid'; $sql.= ' WHERE l.fk_commande = '.$commande->id; @@ -1188,7 +1211,7 @@ else print ' '; print ' '; print ' '; - print ''; + print "\n"; } $var=true; while ($i < $num) @@ -1205,25 +1228,40 @@ else print ''; if ($objp->fk_product_type) print img_object($langs->trans('ShowService'),'service'); else print img_object($langs->trans('ShowProduct'),'product'); - print ' '.$objp->ref.' - '.stripslashes(nl2br($objp->product)); - print ($objp->description && $objp->description!=$objp->product)?'
'.stripslashes(nl2br($objp->description)):''; - + print ' '.$objp->ref.' - '.nl2br($objp->product); + print ($objp->description && $objp->description!=$objp->product)?'
'.nl2br($objp->description):''; if ($conf->global->COM_ADD_PROD_DESC && !$conf->global->PRODUIT_CHANGE_PROD_DESC) { - print '
'.nl2br(stripslashes($objp->product_desc)); + print '
'.nl2br($objp->product_desc); } - print ''; } else { - print ''.stripslashes(nl2br($objp->description)); + print ''; + if (($objp->info_bits & 2) == 2) + { + print ''; + print img_object($langs->trans("ShowReduc"),'reduc').' '.$langs->trans("Discount"); + print ''; + if ($objp->description) print ': '.nl2br($objp->description); + } + else + { + print nl2br($objp->description); + } print ''; } print ''.$objp->tva_tx.'%'; print ''.price($objp->subprice).''; - print ''.$objp->qty.''; + print ''; + if (($objp->info_bits & 2) != 2) + { + print $objp->qty; + } + else print ' '; + print ''; if ($objp->remise_percent > 0) { print ''.$objp->remise_percent.'%'; @@ -1287,10 +1325,10 @@ else if ($objp->fk_product_type) print img_object($langs->trans('ShowService'),'service'); else print img_object($langs->trans('ShowProduct'),'product'); print ' '.$objp->ref.''; - print ' - '.stripslashes(nl2br($objp->product)); + print ' - '.nl2br($objp->product); print '
'; } - print ''; + print ''; print ''; if($soc->tva_assuj == "0") print '0'; @@ -1298,8 +1336,20 @@ else print $html->select_tva('tva_tx',$objp->tva_tx,$mysoc,$soc); print ''; print ''; - print ''; - print '%'; + print ''; + if (($objp->info_bits & 2) != 2) + { + print ''; + } + else print ' '; + print ''; + print ''; + if (($objp->info_bits & 2) != 2) + { + print '%'; + } + else print ' '; + print ''; print ''; print '
'; print ''; @@ -1544,7 +1594,7 @@ else $file = $conf->commande->dir_output . '/'.$comref.'/'.$comref.'.pdf'; if (file_exists($file)) { - print ''.$langs->trans('Send').''; + print ''.$langs->trans('SendByMail').''; } } } @@ -1764,8 +1814,8 @@ else { dolibarr_print_error($db,$result); exit; - } - } + } + } print '
'; print_titre($langs->trans('SendOrderByMail')); diff --git a/htdocs/compta/commande/fiche.php b/htdocs/compta/commande/fiche.php index 1b73725a531..657f1cfce79 100644 --- a/htdocs/compta/commande/fiche.php +++ b/htdocs/compta/commande/fiche.php @@ -20,9 +20,9 @@ * $Id$ * $Source$ */ - + /** - \file htdocs/compta/fiche.php + \file htdocs/compta/commande/fiche.php \ingroup commande \brief Fiche commande \version $Revision$ @@ -43,7 +43,7 @@ $user->getrights('commande'); if (! $user->rights->commande->lire) accessforbidden(); // Sécurité accés client -if ($user->societe_id > 0) +if ($user->societe_id > 0) { $action = ''; $socidp = $user->societe_id; @@ -52,9 +52,9 @@ if ($user->societe_id > 0) /* * Actions - */ + */ -if ($_GET["action"] == 'facturee') +if ($_GET["action"] == 'facturee') { $commande = new Commande($db); $commande->fetch($_GET["id"]); @@ -73,7 +73,7 @@ $html = new Form($db); /* Mode vue et edition */ /* */ /* *************************************************************************** */ - + if ($_GET["id"] > 0) { $commande = new Commande($db); @@ -123,7 +123,7 @@ if ($_GET["id"] > 0) } print ''; print ''; - + // Société print ''.$langs->trans('Company').''; @@ -136,11 +136,21 @@ if ($_GET["id"] > 0) else print $langs->trans("CompanyHasNoRelativeDiscount"); $absolute_discount=$soc->getCurrentDiscount(); print '. '; - if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie)); - else print $langs->trans("CompanyHasNoAbsoluteDiscount"); - print '.'; + if ($absolute_discount) + { + if ($commande->statut > 0) + { + print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie)); + } + else + { + print '
'; + print $html->form_remise_dispo($_SERVER["PHP_SELF"].'?id='.$commande->id,0,'remise_id',$soc->id,$absolute_discount); + } + } + else print $langs->trans("CompanyHasNoAbsoluteDiscount").'.'; print ''; - + // Date print ''.$langs->trans('Date').''; print ''.dolibarr_print_date($commande->date,'%A %d %B %Y').''; @@ -154,13 +164,13 @@ if ($_GET["id"] > 0) } print ''; print ''; - + // Date de livraison print ''; print ''; - + if (1 == 2 && $_GET['action'] != 'editdate_livraison' && $commande->brouillon) print ''; print '
'; print $langs->trans('DateDelivery'); print 'id.'">'.img_edit($langs->trans('SetDateDelivery'),1).'
'; print ''; @@ -178,21 +188,21 @@ if ($_GET["id"] > 0) } print ''; print ''.$langs->trans('NotePublic').' :
'; - print nl2br($commande->note_public); + print nl2br($commande->note_public); print ''; print ''; - - + + // Adresse de livraison print ''; print ''; - + if (1 == 2 && $_GET['action'] != 'editdelivery_adress' && $commande->brouillon) print ''; print '
'; print $langs->trans('DeliveryAddress'); print 'socidp.'&id='.$commande->id.'">'.img_edit($langs->trans('SetDeliveryAddress'),1).'
'; print ''; - + if ($_GET['action'] == 'editdelivery_adress') { $html->form_adresse_livraison($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->adresse_livraison_id,$_GET['socid'],'adresse_livraison_id','commande',$commande->id); @@ -202,13 +212,13 @@ if ($_GET["id"] > 0) $html->form_adresse_livraison($_SERVER['PHP_SELF'].'?id='.$commande->id,$commande->adresse_livraison_id,$_GET['socid'],'none','commande',$commande->id); } print ''; - + // Conditions et modes de réglement print ''; print ''; - + if ($_GET['action'] != 'editconditions' && $commande->brouillon) print ''; print '
'; print $langs->trans('PaymentConditionsShort'); print 'id.'">'.img_edit($langs->trans('SetConditions'),1).'
'; print ''; @@ -263,36 +273,36 @@ if ($_GET["id"] > 0) // Lignes de 3 colonnes // Total HT - print ''.$langs->trans('TotalHT').''; + print ''.$langs->trans('AmountHT').''; print ''.price($commande->total_ht).''; print ''.$langs->trans('Currency'.$conf->monnaie).''; // Total TVA - print ''.$langs->trans('TotalVAT').''.price($commande->total_tva).''; + print ''.$langs->trans('AmountVAT').''.price($commande->total_tva).''; print ''.$langs->trans('Currency'.$conf->monnaie).''; - + // Total TTC - print ''.$langs->trans('TotalTTC').''.price($commande->total_ttc).''; + print ''.$langs->trans('AmountTTC').''.price($commande->total_ttc).''; print ''.$langs->trans('Currency'.$conf->monnaie).''; // Statut print ''.$langs->trans('Status').''; print ''.$commande->getLibStatut(4).''; print ''; - + print ''; - /* - * Lignes de commandes - * - */ - $sql = 'SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice,'; - $sql.= ' p.label as product, p.ref, p.fk_product_type, p.rowid as prodid'; - $sql.= ' FROM '.MAIN_DB_PREFIX."commandedet as l"; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product=p.rowid'; - $sql.= " WHERE l.fk_commande = ".$commande->id; - $sql.= " ORDER BY l.rang"; - + /* + * Lignes de commandes + */ + $sql = 'SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice, l.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."commandedet as l"; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product=p.rowid'; + $sql.= " WHERE l.fk_commande = ".$commande->id; + $sql.= " ORDER BY l.rang, l.rowid"; + $resql = $db->query($sql); if ($resql) { @@ -308,8 +318,8 @@ if ($_GET["id"] > 0) print ''.$langs->trans('VAT').''; print ''.$langs->trans('PriceUHT').''; print ''.$langs->trans('Qty').''; - print ''.$langs->trans('Discount').''; - print ''.$langs->trans('AmountHT').''; + print ''.$langs->trans('ReductionShort').''; + print ''.$langs->trans('AmountHT').''; print ' '; print ' '; print ' '; @@ -328,21 +338,38 @@ if ($_GET["id"] > 0) print ''; if ($objp->fk_product_type) print img_object($langs->trans('ShowService'),'service'); else print img_object($langs->trans('ShowProduct'),'product'); - print ' '.$objp->ref.' - '.stripslashes(nl2br($objp->product)); + print ' '.$objp->ref.' - '.nl2br($objp->product); print ($objp->description && $objp->description!=$objp->product)?'
'.stripslashes(nl2br($objp->description)):''; print ''; } else { - print ''.stripslashes(nl2br($objp->description)); + print ''; + if (($objp->info_bits & 2) == 2) + { + print ''; + print img_object($langs->trans("ShowReduc"),'reduc').' '.$langs->trans("Discount"); + print ''; + if ($objp->description) print ': '.nl2br($objp->description); + } + else + { + print nl2br($objp->description); + } print "\n"; } print ''.$objp->tva_tx.'%'; print ''.price($objp->subprice)."\n"; - print ''.$objp->qty.''; - + print ''; + if (($objp->info_bits & 2) != 2) + { + print $objp->qty; + } + else print ' '; + print ''; + if ($objp->remise_percent > 0) { print ''.$objp->remise_percent."%\n"; @@ -372,7 +399,7 @@ if ($_GET["id"] > 0) /* * Lignes de remise */ - + // Réductions relatives (Remises-Ristournes-Rabbais) /* Une réduction doit s'appliquer obligatoirement sur des lignes de factures et non globalement @@ -431,7 +458,7 @@ if ($_GET["id"] > 0) print ''; */ - // Réductions (Remises-Ristournes-Rabbais) + // Remises absolue /* Les remises absolues doivent s'appliquer par ajout de lignes spécialisées $var=!$var; print '
'; diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index bc9cbc256e3..1010f0e866e 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -110,12 +110,22 @@ if ($_REQUEST['action'] == 'setremisepercent' && $user->rights->facture->creer) $_GET['facid']=$_REQUEST['facid']; } -if ($_REQUEST['action'] == 'setremiseabsolue' && $user->rights->facture->creer) +if ($_POST['action'] == "setabsolutediscount" && $user->rights->propale->creer) { - $fac = new Facture($db); - $fac->fetch($_REQUEST['facid']); - $result = $fac->set_remise_absolue($user, $_POST['remise_absolue']); - $_GET['facid']=$_REQUEST['facid']; + if ($_POST["remise_id"]) + { + $fac = new Facture($db); + $fac->id=$_GET['facid']; + $ret=$fac->fetch($_GET['facid']); + if ($ret > 0) + { + $fac->insert_discount($_POST["remise_id"]); + } + else + { + dolibarr_print_error($db,$fac->error); + } + } } if ($_POST['action'] == 'classin') @@ -1023,11 +1033,13 @@ if ($_GET['action'] == 'create') print '     '; if ($conf->service->enabled) { - print ''.$langs->trans('ServiceLimitedDuration').''; + print ''.$langs->trans('ServiceLimitedDuration').''; } + print ''; for ($i = 1 ; $i <= $NBLINES ; $i++) { - print ''; + print ''; + print ''; // multiprix if($conf->global->PRODUIT_MULTIPRICES == 1) $html->select_produits('','idprod'.$i,'',$conf->produit->limit_size,$soc->price_level); @@ -1110,10 +1122,12 @@ if ($_GET['action'] == 'create') print ''.$langs->trans('Qty').''; print ''.$langs->trans('ReductionShort').''; - // Lignes de propal produits prédéfinis - $sql = 'SELECT pt.rowid, p.label as product, p.ref, pt.tva_tx, pt.price, pt.qty, p.rowid as prodid, pt.remise_percent, pt.description'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'propaldet as pt, '.MAIN_DB_PREFIX.'product as p WHERE pt.fk_product = p.rowid AND pt.fk_propal = '.$_GET['propalid']; - $sql .= ' ORDER BY pt.rowid ASC'; + // Lignes de propal + $sql = 'SELECT p.label as product, p.ref, p.rowid as prodid,'; + $sql.= ' pt.rowid, pt.tva_tx, pt.price, pt.qty, pt.remise_percent, pt.description, pt.info_bits'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'propaldet as pt LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pt.fk_product = p.rowid'; + $sql.= ' WHERE pt.fk_propal = '.$_GET['propalid']; + $sql.= ' ORDER BY pt.rowid ASC'; $result = $db->query($sql); if ($result) { @@ -1124,16 +1138,30 @@ if ($_GET['action'] == 'create') { $objp = $db->fetch_object($result); $var=!$var; - print ''.img_object($langs->trans(''),'product').' '.$objp->ref.''; - print $objp->product?' - '.$objp->product:''; + print ''; + if ($objp->info_bits == 2) + { + print img_object($langs->trans(''),'reduc').' '.$langs->trans("Discount"); + } + else if ($objp->prodid) + { + print ''.img_object($langs->trans(''),'product').' '.$objp->ref.''; + print $objp->product?' - '.$objp->product:''; + } + else + { + print ' '; + } print "\n"; print ''; - print stripslashes(nl2br(dolibarr_trunc($objp->description,60))); + print nl2br(dolibarr_trunc($objp->description,60)); print ''; print ''.$objp->tva_tx.'%'; print ''.price($objp->price).''; print ''.$objp->qty.''; - print ''.$objp->remise_percent.'%'; + print ''; + print $objp->info_bits != 2 ? $objp->remise_percent.'%' : ' '; + print ''; print ''; $i++; } @@ -1142,36 +1170,6 @@ if ($_GET['action'] == 'create') { dolibarr_print_error($db); } - // Lignes de propal non produits prédéfinis - $sql = 'SELECT pt.rowid, pt.description as product, pt.tva_tx, pt.price, pt.qty, pt.remise_percent'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'propaldet as pt '; - $sql .= ' WHERE pt.fk_propal = '.$_GET['propalid']; - $sql .= ' AND (pt.fk_product = 0 or pt.fk_product is null)'; - $sql .= ' ORDER BY pt.rowid ASC'; - $result=$db->query($sql); - if ($result) - { - $num = $db->num_rows($result); - $i = 0; - while ($i < $num) - { - $objp = $db->fetch_object($result); - $var=!$var; - print ' '; - print ''.dolibarr_trunc($objp->product,60).''; - print ''.$objp->tva_tx.'%'; - print ''.price($objp->price).''; - print ''.$objp->qty.''; - print ''.$objp->remise_percent.'%'; - print ''; - $i++; - } - } - else - { - dolibarr_print_error($db); - } - print ''; } @@ -1190,10 +1188,10 @@ if ($_GET['action'] == 'create') print ''.$langs->trans('Qty').''; print ''.$langs->trans('ReductionShort').''; - $sql = 'SELECT pt.rowid, pt.subprice, pt.tva_tx, pt.qty, pt.remise_percent, pt.description,'; + $sql = 'SELECT pt.rowid, pt.subprice, pt.tva_tx, pt.qty, pt.remise_percent, pt.description, pt.info_bits,'; $sql.= ' p.label as product, p.ref, p.rowid as prodid'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet as pt, '.MAIN_DB_PREFIX.'product as p'; - $sql.= ' WHERE pt.fk_product = p.rowid AND pt.fk_commande = '.$commande->id; + $sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet as pt LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pt.fk_product = p.rowid'; + $sql.= ' WHERE pt.fk_commande = '.$commande->id; $sql.= ' ORDER BY pt.rowid ASC'; $result = $db->query($sql); @@ -1206,16 +1204,30 @@ if ($_GET['action'] == 'create') { $objp = $db->fetch_object($result); $var=!$var; - print ''.img_object($langs->trans(''),'product').' '.$objp->ref.''; - print $objp->product?' - '.$objp->product:''; + print ''; + if ($objp->info_bits == 2) + { + print img_object($langs->trans(''),'reduc').' '.$langs->trans("Discount"); + } + else if ($objp->prodid) + { + print ''.img_object($langs->trans(''),'product').' '.$objp->ref.''; + print $objp->product?' - '.$objp->product:''; + } + else + { + print ' '; + } print "\n"; print ''; - print stripslashes(nl2br(dolibarr_trunc($objp->description,60))); + print nl2br(dolibarr_trunc($objp->description,60)); print ''; print ''.$objp->tva_tx.'%'; print ''.price($objp->subprice).''; print ''.$objp->qty.''; - print ''.$objp->remise_percent.'%'; + print ''; + print $objp->info_bits != 2 ? $objp->remise_percent.'%' : ' '; + print ''; print ''; $i++; } @@ -1224,37 +1236,6 @@ if ($_GET['action'] == 'create') { dolibarr_print_error($db); } - // Lignes de commande non produits prédéfinis - $sql = 'SELECT pt.rowid, pt.description as product, pt.tva_tx, pt.subprice, pt.qty, pt.remise_percent'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'commandedet as pt'; - $sql .= ' WHERE pt.fk_commande = '.$commande->id; - $sql .= ' AND (pt.fk_product = 0 or pt.fk_product is null)'; - $sql .= ' ORDER BY pt.rowid ASC'; - - $result=$db->query($sql); - if ($result) - { - $num = $db->num_rows($result); - $i = 0; - while ($i < $num) - { - $objp = $db->fetch_object($result); - $var=!$var; - print ' '; - print ''.dolibarr_trunc($objp->product,60).''; - print ''.$objp->tva_tx.'%'; - print ''.price($objp->subprice).''; - print ''.$objp->qty.''; - print ''.$objp->remise_percent.'%'; - print ''; - $i++; - } - } - else - { - dolibarr_print_error($db); - } - print ''; } @@ -1274,12 +1255,12 @@ if ($_GET['action'] == 'create') print ''.$langs->trans('ReductionShort').''; // Lignes de contrat produits prédéfinis - $sql = 'SELECT pt.rowid, pt.subprice, pt.tva_tx, pt.qty, pt.remise_percent, pt.description,'; + $sql = 'SELECT pt.rowid, pt.subprice, pt.tva_tx, pt.qty, pt.remise_percent, pt.description, pt.info_bits,'; $sql.= ' pt.date_ouverture_prevue as date_debut_prevue, pt.date_ouverture as date_debut_reel,'; $sql.= ' pt.date_fin_validite as date_fin_prevue, pt.date_cloture as date_fin_reel,'; $sql.= ' p.label as product, p.ref, p.rowid as prodid'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'contratdet as pt, '.MAIN_DB_PREFIX.'product as p'; - $sql.= ' WHERE pt.fk_product = p.rowid AND pt.fk_contrat = '.$contrat->id; + $sql.= ' FROM '.MAIN_DB_PREFIX.'contratdet as pt LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pt.fk_product = p.rowid'; + $sql.= ' WHERE pt.fk_contrat = '.$contrat->id; $sql.= ' ORDER BY pt.rowid ASC'; $result = $db->query($sql); @@ -1292,15 +1273,26 @@ if ($_GET['action'] == 'create') { $objp = $db->fetch_object($result); $var=!$var; - print ''.img_object($langs->trans(''),'service').' '.$objp->ref.''; - print $objp->product?' - '.$objp->product:''; - // Plage de dates - $date_start=$objp->date_debut_prevue; - if ($objp->date_debut_reel) $date_start=$objp->date_debut_reel; - $date_end=$objp->date_fin_prevue; - if ($objp->date_fin_reel) $date_end=$objp->date_fin_reel; - print_date_range($date_start,$date_end); - + print ''; + if ($objp->info_bits == 2) + { + print img_object($langs->trans(''),'reduc').' '.$langs->trans("Discount"); + } + else if ($objp->prodid) + { + print ''.img_object($langs->trans(''),'service').' '.$objp->ref.''; + print $objp->product?' - '.$objp->product:''; + // Plage de dates + $date_start=$objp->date_debut_prevue; + if ($objp->date_debut_reel) $date_start=$objp->date_debut_reel; + $date_end=$objp->date_fin_prevue; + if ($objp->date_fin_reel) $date_end=$objp->date_fin_reel; + print_date_range($date_start,$date_end); + } + else + { + print ' '; + } print "\n"; print ''; print dolibarr_trunc($objp->description,60); @@ -1308,39 +1300,9 @@ if ($_GET['action'] == 'create') print ''.$objp->tva_tx.'%'; print ''.price($objp->subprice).''; print ''.$objp->qty.''; - print ''.$objp->remise_percent.'%'; - print ''; - $i++; - } - } - else - { - dolibarr_print_error($db); - } - // Lignes de contrat non produits prédéfinis - $sql = 'SELECT pt.rowid, pt.description as product, pt.tva_tx, pt.subprice, pt.qty, pt.remise_percent,'; - $sql.= ' pt.date_ouverture_prevue as date_debut_prevue, pt.date_ouverture as date_debut_reel,'; - $sql.= ' pt.date_fin_validite as date_fin_prevue, pt.date_cloture as date_fin_reel'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'contratdet as pt'; - $sql.= ' WHERE pt.fk_contrat = '.$contrat->id; - $sql.= ' AND (pt.fk_product = 0 or pt.fk_product is null)'; - $sql.= ' ORDER BY pt.rowid ASC'; - - $result=$db->query($sql); - if ($result) - { - $num = $db->num_rows($result); - $i = 0; - while ($i < $num) - { - $objp = $db->fetch_object($result); - $var=!$var; - print ' '; - print ''.dolibarr_trunc($objp->product,60).''; - print ''.$objp->tva_tx.'%'; - print ''.price($objp->subprice).''; - print ''.$objp->qty.''; - print ''.$objp->remise_percent.'%'; + print ''; + print $objp->info_bits != 2 ? $objp->remise_percent.'%' : ' '; + print ''; print ''; $i++; } @@ -1436,17 +1398,17 @@ else */ print ''; - // Reference - print ''; - - // Ref client + // Reference + print ''; + + // Ref client print ''; // Ligne info remises tiers - print ''; // Dates @@ -1686,7 +1659,7 @@ else * Lignes de factures */ $sql = 'SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_taux,'; - $sql.= ' l.remise_percent, l.subprice,'; + $sql.= ' l.remise_percent, l.subprice, l.info_bits,'; $sql.= ' '.$db->pdate('l.date_start').' as date_start,'; $sql.= ' '.$db->pdate('l.date_end').' as date_end,'; $sql.= ' p.ref, p.fk_product_type, p.label as product,'; @@ -1749,13 +1722,30 @@ else } else { - print '\n"; } print ''; print '\n"; - print ''; + print ''; if ($objp->remise_percent > 0) { print '\n"; @@ -1819,19 +1809,31 @@ else if ($objp->fk_product_type) print img_object($langs->trans('ShowService'),'service'); else print img_object($langs->trans('ShowProduct'),'product'); print ' '.$objp->ref.''; - print ' - '.stripslashes(nl2br($objp->product)); + print ' - '.nl2br($objp->product); print '
'; } - print ''; + print ''; print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; print ''; print '' . "\n"; @@ -2111,13 +2113,13 @@ else // Envoyer if ($fac->statut == 1 && $user->rights->facture->envoyer) { - print ' '.$langs->trans('Send').''; + print ' '.$langs->trans('SendByMail').''; } // Envoyer une relance if ($fac->statut == 1 && price($resteapayer) > 0 && $user->rights->facture->envoyer) { - print ' '.$langs->trans('SendRemind').''; + print ' '.$langs->trans('SendRemindByMail').''; } // Emettre paiement diff --git a/htdocs/discount.class.php b/htdocs/discount.class.php new file mode 100644 index 00000000000..2d86c490b8a --- /dev/null +++ b/htdocs/discount.class.php @@ -0,0 +1,95 @@ + + * Copyright (C) 2004-2006 Laurent Destailleur + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + * $Source$ + */ + +/** + \file htdocs/discount.class.php + \ingroup propal,facture,commande + \brief Fichier de la classe de gestion des remises + \version $Revision$ +*/ + + +/** + \class DiscountAbsolute + \brief Classe permettant la gestion des remises fixes +*/ + +class DiscountAbsolute +{ + var $id; + var $db; + + + /** + * \brief Constructeur de la classe + * \param DB handler accès base de données + */ + function DiscountAbsolute($DB) + { + $this->db = $DB; + } + + + /** + * \brief Charge objet remiset depuis la base + * \param rowid id du projet à charger + * \return int <0 si ko, =0 si non trouvé, >0 si ok + */ + function fetch($rowid) + { + $sql = "SELECT fk_soc, amount_ht, fk_user, fk_facture, description,"; + $sql.= " ".$this->db->pdate("datec")." as datec"; + $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except"; + $sql.= " WHERE rowid=".$rowid; + + $resql = $this->db->query($sql); + if ($resql) + { + if ($this->db->num_rows($resql)) + { + $obj = $this->db->fetch_object($resql); + + $this->id = $rowid; + $this->fk_soc = $obj->fk_soc; + $this->amount_ht = $obj->amount_ht; + $this->fk_user = $obj->fk_user; + $this->fk_facture = $obj->fk_facture; + $this->description = $obj->description; + $this->datec = $obj->datec; + + $this->db->free($resql); + return 1; + } + else + { + $this->db->free($resql); + return 0; + } + } + else + { + $this->error=$this->db->error(); + return -1; + } + } +} +?> diff --git a/htdocs/expedition/commande.php b/htdocs/expedition/commande.php index be82af95924..bd9169b2ac2 100644 --- a/htdocs/expedition/commande.php +++ b/htdocs/expedition/commande.php @@ -278,16 +278,16 @@ if ($_GET["id"] > 0) // Lignes de 3 colonnes // Total HT - print ''; + print ''; print ''; print ''; // Total TVA - print ''; + print ''; print ''; // Total TTC - print ''; + print ''; print ''; // Statut diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index 74120d37a9d..9b9e4cd1331 100644 --- a/htdocs/facture.class.php +++ b/htdocs/facture.class.php @@ -164,7 +164,7 @@ class Facture extends CommonObject $sql.= ' datef,'; $sql.= ' note,'; $sql.= ' note_public,'; - $sql.= ' ref_client,'; + $sql.= ' ref_client,'; $sql.= ' fk_user_author, fk_projet,'; $sql.= ' fk_cond_reglement, fk_mode_reglement, date_lim_reglement, model_pdf) '; $sql.= " VALUES ("; @@ -470,6 +470,74 @@ class Facture extends CommonObject } + /** + * \brief Ajout d'une ligne remise fixe dans la facture, en base + * \param idremise Id de la remise fixe + * \return int >0 si ok, <0 si ko + */ + 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) + { + $facligne=new FactureLigne($this->db); + $facligne->fk_facture=$this->id; + $facligne->fk_remise_except=$remise->id; + $facligne->desc=$remise->description; // Description ligne + $facligne->tva_tx=$remise->tva_tx; + $facligne->subprice=-$remise->amount_ht; + $facligne->price=-$remise->amount_ht; + $facligne->fk_product=0; // Id produit prédéfini + $facligne->qty=1; + $facligne->remise=0; + $facligne->remise_percent=0; + $facligne->rang=-1; + $facligne->info_bits=2; + + $tabprice=calcul_price_total($facligne->qty, $facligne->subprice, 0,$facligne->tva_tx); + $facligne->total_ht = $tabprice[0]; + $facligne->total_tva = $tabprice[1]; + $facligne->total_ttc = $tabprice[2]; + + $result=$facligne->insert(); + if ($result > 0) + { + $result=$this->update_price($this->id); + if ($result > 0) + { + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + return -1; + } + } + else + { + $this->error=$facligne->error; + $this->db->rollback(); + return -2; + } + } + else + { + $this->db->rollback(); + return -2; + } + } + + /** * \brief Classe la facture dans un projet * \param projid Id du projet dans lequel classer la facture @@ -1033,22 +1101,6 @@ class Facture extends CommonObject $price = ($pu - $remise); } - // Récupère rang max de la facture dans $rangmax - $sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.'facturedet'; - $sql.= ' WHERE fk_facture ='.$facid; - $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 FactureLigne($this->db); @@ -1064,7 +1116,7 @@ class Facture extends CommonObject $ligne->date_start=$date_start; $ligne->date_end=$date_end; $ligne->ventil=$ventil; - $ligne->rang=($rangmax+1); + $ligne->rang=-1; $ligne->info_bits=$info_bits; $ligne->total_ht=$total_ht; $ligne->total_tva=$total_tva; @@ -2191,8 +2243,29 @@ class FactureLigne */ function insert() { + dolibarr_syslog("FactureLigne.class::insert rang=".$this->rang); $this->db->begin(); + $rangtouse=$this->rang; + if ($rangtouse == -1) + { + // Récupère rang max de la facture dans $rangmax + $sql = 'SELECT max(rang) as max FROM '.MAIN_DB_PREFIX.'facturedet'; + $sql.= ' WHERE fk_facture ='.$this->fk_facture; + $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.'facturedet'; $sql.= ' (fk_facture, description, price, qty, tva_taux,'; @@ -2218,14 +2291,14 @@ class FactureLigne else { $sql.='null,'; } $sql.= ' '.$this->fk_code_ventilation.','; $sql.= ' '.$this->fk_export_compta.','; - $sql.= ' '.$this->rang.','; + $sql.= ' '.$rangtouse.','; $sql.= " '".$this->info_bits."',"; $sql.= " '".price2num($this->total_ht)."',"; $sql.= " '".price2num($this->total_tva)."',"; $sql.= " '".price2num($this->total_ttc)."'"; $sql.= ')'; - dolibarr_syslog("FactureLigne::insert sql=$sql"); + dolibarr_syslog("FactureLigne.class::insert sql=$sql"); $resql=$this->db->query($sql); if ($resql) diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index da4b2543462..12280ad28b2 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -34,8 +34,8 @@ AddBill=Add invoice DeleteBill=Delete invoice SearchABill=Search an invoice CancelBill=Cancel an invoice -Send=Send -SendRemind=Send reminder +SendByMail=EMail +SendRemindByMail=EMail reminder DoPaiement=Do payment DoPayment=Do payment VAT=VAT diff --git a/htdocs/langs/en_US/companies.lang b/htdocs/langs/en_US/companies.lang index 6d4e6370d75..9af434b1d74 100644 --- a/htdocs/langs/en_US/companies.lang +++ b/htdocs/langs/en_US/companies.lang @@ -82,7 +82,7 @@ CustomerRelativeDiscountShort=Relative discount CustomerAbsoluteDiscountShort=Absolute discount 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 +CompanyHasAbsoluteDiscount=This customer still has discount credits for %s %s 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/orders.lang b/htdocs/langs/en_US/orders.lang index cbaf1e192ba..151ce7fbafc 100755 --- a/htdocs/langs/en_US/orders.lang +++ b/htdocs/langs/en_US/orders.lang @@ -22,7 +22,7 @@ StatusOrderOnProcessShort=On process StatusOrderProcessedShort=Processed StatusOrderToBillShort=To bill StatusOrderCanceled=Canceld -StatusOrderDraft=Draft +StatusOrderDraft=Draft (need to be validated) StatusOrderValidated=Validated StatusOrderOnProcess=On process StatusOrderProcessed=Processed @@ -71,7 +71,7 @@ RefCustomer=Ref. customer RefCustomerOrder=Ref. customer order CustomerOrder=Customer order RefCustomerOrderShort=Ref. cust. order -SendPropalByMail=Send order by mail +SendOrderByMail=Send order by mail ActionsOnOrder=Actions on order NoArticleOfTypeProduct=No article of type 'product' so no shippable article for this order OrderMode=Order method diff --git a/htdocs/langs/fr_BE/bills.lang b/htdocs/langs/fr_BE/bills.lang index 0fdcf4536c6..fec2b9bd8ac 100644 --- a/htdocs/langs/fr_BE/bills.lang +++ b/htdocs/langs/fr_BE/bills.lang @@ -4,8 +4,8 @@ Bills=Factures ClassifyPayed=Classer 'Payée' ClassifyCanceled=Classer 'Abandonnée' CreateBill=Créer Facture -Send=Envoyer -SendRemind=Envoyer un rappel +SendByMail=Envoyer +SendRemindByMail=Envoyer rappel DoPaiement=Emettre un paiement VAT=TVA VATRate=Taux TVA diff --git a/htdocs/langs/fr_FR/bills.lang b/htdocs/langs/fr_FR/bills.lang index 52d9f2e3c02..dec70a4bfde 100644 --- a/htdocs/langs/fr_FR/bills.lang +++ b/htdocs/langs/fr_FR/bills.lang @@ -34,8 +34,8 @@ AddBill=Cr DeleteBill=Supprimer facture SearchABill=Rechercher une facture CancelBill=Annuler une facture -Send=Envoyer -SendRemind=Envoyer rappel +SendByMail=Envoyer +SendRemindByMail=Envoyer rappel DoPaiement=Émettre paiement DoPayment=Émettre paiement VAT=TVA diff --git a/htdocs/langs/fr_FR/orders.lang b/htdocs/langs/fr_FR/orders.lang index c877e434de6..61d1826ef80 100755 --- a/htdocs/langs/fr_FR/orders.lang +++ b/htdocs/langs/fr_FR/orders.lang @@ -22,7 +22,7 @@ StatusOrderOnProcessShort=En cours StatusOrderProcessedShort=Traitée StatusOrderToBillShort=À facturer StatusOrderCanceled=Annulée -StatusOrderDraft=Brouillon +StatusOrderDraft=Brouillon (à valider) StatusOrderValidated=Validée StatusOrderOnProcess=Traitement en cours StatusOrderProcessed=Traitée diff --git a/htdocs/propal.class.php b/htdocs/propal.class.php index 224b5c7ff81..b9397dc6d17 100644 --- a/htdocs/propal.class.php +++ b/htdocs/propal.class.php @@ -147,13 +147,9 @@ class Propal extends CommonObject } /** - * \brief Ajout d'un produit dans la proposition, en base - * \param idproduct Id du produit à ajouter - * \param qty Quantité - * \param remise_percent Remise relative effectuée sur le produit - * \param p_desc Descriptif optionnel - * \return int >0 si ok, <0 si ko - * \see add_product + * \brief Ajout d'une ligne remise fixe dans la proposition, en base + * \param idremise Id de la remise fixe + * \return int >0 si ok, <0 si ko */ function insert_discount($idremise) { @@ -1857,52 +1853,6 @@ class Propal extends CommonObject } } - /** - * \brief Charge l'objet propal en mémoire avec propal dont l'id est passé en argument - * \param $src_propal_id Id de la propal source - * \return int >0 si ok, <0 si ko - * \see fetch - */ - function load_from($src_propal_id) - { - $src_propal = new Propal($this->db); - if($src_propal->fetch($src_propal_id) < 0) - { - dolibarr_syslog("Propal::load_from: Erreur de lecture de la propal source."); - return -1; - } - $this->datep = $src_propal->datep; - $this->fin_validite = $src_propal->fin_validite; - $this->date = $src_propal->date; - $this->ref = $src_propal->ref; - $this->price = $src_propal->price; - $this->remise = $src_propal->remise; - $this->remise_percent = $src_propal->remise_percent; - $this->remise_absolue = $src_propal->remise_absolue; - $this->total = $src_propal->total; - $this->total_ht = $src_propal->total_ht; - $this->total_tva = $src_propal->total_tva; - $this->total_ttc = $src_propal->total_ttc; - $this->socidp = $src_propal->socidp; - $this->projetidp = $src_propal->projetidp; - $this->contactid = $src_propal->contactid; - $this->modelpdf = $src_propal->modelpdf; - $this->note = $src_propal->note; - $this->note_public = $src_propal->note_public; - $this->statut = $src_propal->statut; - $this->statut_libelle = $src_propal->statut_libelle; - $this->cond_reglement_id = $src_propal->cond_reglement_id; - $this->mode_reglement_id = $src_propal->mode_reglement_id; - $this->date_livraison = $src_propal->date_livraison; - $this->adresse_livraison_id = $src_propal->adresse_livraison_id; - $this->user_author_id = $src_propal->user_author_id; - - $this->cond_reglement = $src_propal->cond_reglement; - $this->cond_reglement_code=$src_propal->cond_reglement_code; - $this->ref_url = $src_propal->ref_url; - $this->lignes = $src_propal->lignes; - return 1; - } /** * \brief Insert en base un objet propal complétement définie par ses données membres (resultant d'une copie par exemple). @@ -2171,7 +2121,7 @@ class PropaleLigne */ function insert() { - dolibarr_syslog("PropaleLigne::insert rang=".$this->rang); + dolibarr_syslog("PropaleLigne.class::insert rang=".$this->rang); $this->db->begin(); $rangtouse=$this->rang; @@ -2221,7 +2171,7 @@ class PropaleLigne $sql.= " '".price2num($this->total_ttc)."'"; $sql.= ')'; - dolibarr_syslog("PropaleLigne::insert sql=$sql"); + dolibarr_syslog("PropaleLigne.class::insert sql=$sql"); $resql=$this->db->query($sql); if ($resql) diff --git a/htdocs/theme/dev/img/object_reduc.png b/htdocs/theme/dev/img/object_reduc.png new file mode 100644 index 00000000000..4d5f811a891 Binary files /dev/null and b/htdocs/theme/dev/img/object_reduc.png differ diff --git a/htdocs/theme/dolibarr/img/object_reduc.png b/htdocs/theme/dolibarr/img/object_reduc.png new file mode 100644 index 00000000000..4d5f811a891 Binary files /dev/null and b/htdocs/theme/dolibarr/img/object_reduc.png differ diff --git a/htdocs/theme/eldy/img/object_reduc.png b/htdocs/theme/eldy/img/object_reduc.png new file mode 100644 index 00000000000..4d5f811a891 Binary files /dev/null and b/htdocs/theme/eldy/img/object_reduc.png differ diff --git a/htdocs/theme/freelug/img/object_reduc.png b/htdocs/theme/freelug/img/object_reduc.png new file mode 100644 index 00000000000..4d5f811a891 Binary files /dev/null and b/htdocs/theme/freelug/img/object_reduc.png differ diff --git a/htdocs/theme/yellow/img/object_reduc.png b/htdocs/theme/yellow/img/object_reduc.png new file mode 100644 index 00000000000..4d5f811a891 Binary files /dev/null and b/htdocs/theme/yellow/img/object_reduc.png differ
'.$langs->trans('Ref').''.$fac->ref.'
'.$langs->trans('Ref').''.$fac->ref.'
'; print ''; if ($_GET['action'] != 'refcdeclient' && $fac->brouillon) print ''; print '
'; print $langs->trans('RefCustomer').''; print ''.img_edit($langs->trans('Edit')).'
'; - print '
'; + print ''; if ($user->rights->facture->creer && $_GET['action'] == 'refcdeclient') { print ''; @@ -1468,13 +1430,24 @@ else print '
'.$langs->trans('Discounts').''; + print '
'.$langs->trans('Discounts').''; if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client); else print $langs->trans("CompanyHasNoRelativeDiscount"); + $absolute_discount=$soc->getCurrentDiscount(); print '. '; - if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie)); - else print $langs->trans("CompanyHasNoAbsoluteDiscount"); - print '.'; + if ($absolute_discount) + { + if ($fac->statut > 0) + { + print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie)); + } + else + { + print '
'; + print $html->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$fac->id,0,'remise_id',$soc->id,$absolute_discount); + } + } + else print $langs->trans("CompanyHasNoAbsoluteDiscount").'.'; print '
'.stripslashes(nl2br($objp->description)); - print_date_range($objp->date_start,$objp->date_end); + print ''; + if (($objp->info_bits & 2) == 2) + { + print ''; + print img_object($langs->trans("ShowReduc"),'reduc').' '.$langs->trans("Discount"); + print ''; + if ($objp->description) print ': '.nl2br($objp->description); + } + else + { + print nl2br($objp->description); + print_date_range($objp->date_start,$objp->date_end); + } print "'.$objp->tva_taux.'%'.price($objp->subprice)."'.$objp->qty.''; + if (($objp->info_bits & 2) != 2) + { + print $objp->qty; + } + else print ' '; + print ''.$objp->remise_percent."%'; if(! $soc->tva_assuj) print '0'; else print $html->select_tva('tva_tx',$objp->tva_taux,$mysoc,$soc); print '%'; + if (($objp->info_bits & 2) != 2) + { + print ''; + } + else print ' '; + print ''; + if (($objp->info_bits & 2) != 0) + { + print '%'; + } + else print ' '; + print ''; print '
'.$langs->trans('TotalHT').'
'.$langs->trans('AmountHT').''.price($commande->total_ht).''.$langs->trans('Currency'.$conf->monnaie).'
'.$langs->trans('TotalVAT').''.price($commande->total_tva).'
'.$langs->trans('AmountVAT').''.price($commande->total_tva).''.$langs->trans('Currency'.$conf->monnaie).'
'.$langs->trans('TotalTTC').''.price($commande->total_ttc).'
'.$langs->trans('AmountTTC').''.price($commande->total_ttc).''.$langs->trans('Currency'.$conf->monnaie).'