From a53e6f7cfca4ec5dbf9024364efcda815297c66e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 16 Jun 2006 00:33:04 +0000 Subject: [PATCH] Mise a jour des champ total_ht, total_tva et total_ttc au niveau ligne --- htdocs/comm/addpropal.php | 81 +- htdocs/comm/propal.php | 1318 ++++++++++++++-------------- htdocs/commande/commande.class.php | 27 +- htdocs/compta/facture.php | 57 +- htdocs/compta/propal.php | 745 ++++++++-------- htdocs/facture.class.php | 89 +- htdocs/langs/en_US/companies.lang | 1 + htdocs/langs/en_US/main.lang | 1 + htdocs/langs/fr_FR/companies.lang | 1 + htdocs/langs/fr_FR/main.lang | 1 + htdocs/lib/functions.inc.php | 9 +- htdocs/lib/price.lib.php | 13 +- htdocs/master.inc.php | 22 +- htdocs/product.class.php | 1 + htdocs/propal.class.php | 254 ++++-- mysql/migration/2.0.0-2.1.0.sql | 6 +- mysql/tables/llx_propaldet.sql | 4 + 17 files changed, 1341 insertions(+), 1289 deletions(-) diff --git a/htdocs/comm/addpropal.php b/htdocs/comm/addpropal.php index 989d08f9dc0..955fb27ad51 100644 --- a/htdocs/comm/addpropal.php +++ b/htdocs/comm/addpropal.php @@ -212,51 +212,21 @@ if ($_GET["action"] == 'create') } /* - * Destinataire de la propale + * Contact de la propale */ - print "".$langs->trans("Contact")."\n"; - $sql = "SELECT p.idp, p.name, p.firstname, p.poste, p.phone, p.fax, p.email FROM ".MAIN_DB_PREFIX."socpeople as p"; - $sql .= " WHERE p.fk_soc = ".$soc->id; - - if ( $db->query($sql) ) - { - $i = 0 ; - $numdest = $db->num_rows(); - - if ($numdest==0) - { - print 'Cette societe n\'a pas de contact, veuillez en créer un avant de faire votre proposition commerciale
'; - print ''.$langs->trans("AddContact").''; - } - else - { - print "'; - } - - $db->free(); - } - else - { - dolibarr_print_error($db); - } - + print "".$langs->trans("DefaultContact")."\n"; + $html->select_contacts($soc->id,$setcontact,'contactidp',1); print ''; + // Model + print ''; + print ''.$langs->trans("DefaultModel").''; + print ''; + $model=new ModelePDFPropales(); + $liste=$model->liste_modeles($db); + $html->select_array("model",$liste,$conf->global->PROPALE_ADDON_PDF); + print ""; + // Projet if ($conf->projet->enabled) { @@ -266,20 +236,12 @@ if ($_GET["action"] == 'create') $numprojet=$html->select_projects($soc->id,$projetid,'projetidp'); if ($numprojet==0) { - print '   id.'&action=create>'.$langs->trans("AddProject").''; + print '   '.$langs->trans("AddProject").''; } print ''; print ''; } - print ''; - print ''.$langs->trans("Model").''; - print ''; - $model=new ModelePDFPropales(); - $liste=$model->liste_modeles($db); - $html->select_array("model",$liste,$conf->global->PROPALE_ADDON_PDF); - print ""; - print ""; print '
'; @@ -324,7 +286,7 @@ if ($_GET["action"] == 'create') { $lib=$langs->trans("ProductsAndServices"); - print ''; + print '
'; print ''; print ''; print ''; @@ -355,16 +317,11 @@ if ($_GET["action"] == 'create') print '
'.$lib.''.$langs->trans("Qty").'
'; print '
'; - /* - * Si il n'y a pas de contact pour la societe on ne permet pas la creation de propale - */ - if ($numdest > 0) - { - $langs->load("bills"); - print '
'; - print ''; - print '
'; - } + $langs->load("bills"); + print '
'; + print ''; + print '
'; + print ""; } diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 18ea7c2649f..61193fd2ee9 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -152,7 +152,7 @@ if ($_POST['action'] == 'add') $propal = new Propal($db, $_POST['socidp']); /* - * Si on seléctionné une propal à copier, on réalise la copie + * Si on a selectionné une propal à copier, on réalise la copie */ if($_POST['createmode']=='copy' && $_POST['copie_propal']) { @@ -535,8 +535,6 @@ $html = new Form($db); */ if ($_GET['propalid'] > 0) { - $propalid = $_GET['propalid']; - if ($msg) print "$msg
"; $propal = new Propal($db); @@ -558,7 +556,7 @@ if ($_GET['propalid'] > 0) print '
'; } - /* + /* * Confirmation de la suppression d'une ligne produit */ if ($_GET['action'] == 'delete_product_line' && $conf->global->PRODUIT_CONFIRM_DELETE_LINE) @@ -581,683 +579,664 @@ if ($_GET['propalid'] > 0) * Fiche propal * */ - $sql = 'SELECT s.nom, s.idp, p.price, p.fk_projet, p.remise, p.tva, p.total, p.ref, p.fk_statut, p.fk_cond_reglement, p.fk_mode_reglement, '.$db->pdate('p.datep').' as dp, p.note,'; - $sql.= ' x.firstname, x.name, x.fax, x.phone, x.email, p.fk_user_author, p.fk_user_valid, p.fk_user_cloture, p.datec, p.date_valid, p.date_cloture'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'propal as p, '.MAIN_DB_PREFIX.'socpeople as x'; - $sql.= ' WHERE p.fk_soc = s.idp AND p.fk_soc_contact = x.idp AND p.rowid = '.$propal->id; - if ($socidp) $sql .= ' AND s.idp = '.$socidp; + print ''; + + // Ref + print ''; + + // Ref client + print ''; + print ''; + + $rowspan=8; + + // Société + print ''; + print ''; + + // Ligne info remises tiers + print ''; + + // Dates + print ''; + + if ($conf->projet->enabled) $rowspan++; + if ($conf->global->PROPAL_ADD_SHIPPING_DATE) $rowspan++; + if ($conf->global->PROPAL_ADD_DELIVERY_ADDRESS) $rowspan++; + + // Notes + print ''; + print ''; + + // Date fin propal + print ''; + print ''; + print ''; + + + // date de livraison (conditonné sur PROPAL_ADD_SHIPPING_DATE car carac à + // gérer par les commandes et non les propal + if ($conf->global->PROPAL_ADD_SHIPPING_DATE) + { + print ''; + print ''; + } + + // adresse de livraison + if ($conf->global->PROPAL_ADD_DELIVERY_ADDRESS) + { + print ''; + } + + // Conditions et modes de réglement + print ''; + print ''; + + // Mode paiement + print ''; + print ''; + + // Destinataire +/* On gère les contacts sur onglet contact + $langs->load('mails'); + print ''; + print ''; +*/ + + // Projet + if ($conf->projet->enabled) + { + $langs->load("projects"); + print ''; + $numprojet = $societe->has_projects(); + if (! $numprojet) + { + print ''; + } + else + { + if ($propal->statut == 0 && $user->rights->propale->creer) + { + print ''; + } + else + { + if (!empty($propal->projetidp)) + { + print ''; + } + else { + print ''; + } + } + } + print ''; + } + + // Amount + print ''; + print ''; + print ''; + + print ''; + print ''; + print ''; + print ''; + + // Statut + print ''; + print '
'.$langs->trans('Ref').''.$propal->ref_url.'
'; + print ''; + if ($_GET['action'] != 'refclient' && $propal->brouillon) print ''; + print '
'; + print $langs->trans('RefCustomer').''; + print ''.img_edit($langs->trans('Edit')).'
'; + print '
'; + if ($user->rights->propale->creer && $_GET['action'] == 'refclient') + { + print '
'; + print ''; + print ''; + print ' '; + print '
'; + } + else + { + print $propal->ref_client; + } + print '
'.$langs->trans('Company').''.$societe->getNomUrl(1).'
'.$langs->trans('Discounts').''; + if ($societe->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$societe->remise_client); + else print $langs->trans("CompanyHasNoRelativeDiscount"); + $absolute_discount=$societe->getCurrentDiscount(); + 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); + } + else print $langs->trans("CompanyHasNoAbsoluteDiscount").'.'; + print '
'.$langs->trans('Date').''; + print dolibarr_print_date($propal->date,'%a %d %B %Y'); + print ''.$langs->trans('NotePublic').' :
'. nl2br($propal->note_public).'
'; + print ''; + if ($_GET['action'] != 'editecheance' && $propal->brouillon) print ''; + print '
'; + print $langs->trans('DateEndPropal'); + print 'id.'">'.img_edit($langs->trans('SetConditions'),1).'
'; + print '
'; + if ($propal->brouillon && $_GET['action'] == 'editecheance') + { + print '
'; + print ''; + $html->select_date($propal->fin_validite,'ech','','','',"editecheance"); + print ''; + print '
'; + } + else + { + if ($propal->fin_validite) + { + print dolibarr_print_date($propal->fin_validite,'%a %d %B %Y'); + if ($propal->statut == 1 && $propal->fin_validite < (time() - $conf->propal->cloture->warning_delay)) print img_warning($langs->trans("Late")); + } + else + { + print ' '; + } + } + print '
'; + print ''; + if ($_GET['action'] != 'editdate_livraison' && $propal->brouillon) print ''; + print '
'; + print $langs->trans('DateDelivery'); + print 'id.'">'.img_edit($langs->trans('SetDateLivraison'),1).'
'; + print '
'; + if ($_GET['action'] == 'editdate_livraison') + { + print '
'; + print ''; + $html->select_date($propal->date_livraison,'liv_','','','',"editdate_livraison"); + print ''; + print '
'; + } + else + { + print dolibarr_print_date($propal->date_livraison,'%a %d %B %Y'); + } + print '
'; + print ''; + + if ($_GET['action'] != 'editdelivery_adress' && $propal->brouillon) print ''; + print '
'; + print $langs->trans('DeliveryAddress'); + print 'socidp.'&propalid='.$propal->id.'">'.img_edit($langs->trans('SetDeliveryAddress'),1).'
'; + print '
'; + + if ($_GET['action'] == 'editdelivery_adress') + { + $html->form_adresse_livraison($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->adresse_livraison_id,$_GET['socidp'],'adresse_livraison_id','propal',$propal->id); + } + else + { + $html->form_adresse_livraison($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->adresse_livraison_id,$_GET['socidp'],'none','propal',$propal->id); + } + print '
'; + print ''; + if ($_GET['action'] != 'editconditions' && $propal->brouillon) print ''; + print '
'; + print $langs->trans('PaymentConditionsShort'); + print 'id.'">'.img_edit($langs->trans('SetConditions'),1).'
'; + print '
'; + if ($_GET['action'] == 'editconditions') + { + $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->cond_reglement_id,'cond_reglement_id'); + } + else + { + $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->cond_reglement_id,'none'); + } + print '
'; + print ''; + if ($_GET['action'] != 'editmode' && $propal->brouillon) print ''; + print '
'; + print $langs->trans('PaymentMode'); + print 'id.'">'.img_edit($langs->trans('SetMode'),1).'
'; + print '
'; + if ($_GET['action'] == 'editmode') + { + $html->form_modes_reglement($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->mode_reglement_id,'mode_reglement_id'); + } + else + { + $html->form_modes_reglement($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->mode_reglement_id,'none'); + } + 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 '
'.$langs->trans('Project').''; + print $langs->trans("NoProject").''; + print 'id.'&action=create>'.$langs->trans('AddProject').''; + print ''; + print '
'; + print ''; + $form->select_projects($societe->id, $propal->projetidp, 'projetidp'); + print '
'; + print ''; + print ''; + print ''; + $proj = new Project($db); + $proj->fetch($propal->projetidp); + print ''; + print $proj->title; + print ''; + print ' 
'.$langs->trans('AmountHT').''.price($propal->price).''.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans('AmountVAT').''.price($propal->total_tva).''.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans('AmountTTC').''.price($propal->total_ttc).''.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans('Status').''.$propal->getLibStatut(4).'

'; + + /* + * Lignes de propale + */ + print ''; + + $sql = 'SELECT pt.rowid, pt.description, pt.price, pt.fk_product, pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice,'; + $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'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pt.fk_product=p.rowid'; + $sql.= ' WHERE pt.fk_propal = '.$propal->id; + $sql.= ' ORDER BY pt.rang ASC, pt.rowid'; $resql = $db->query($sql); if ($resql) { - if ($db->num_rows($resql)) + $num = $db->num_rows($resql); + $i = 0; $total = 0; + + if ($num) { - $obj = $db->fetch_object($resql); - - $societe = new Societe($db); - $societe->fetch($obj->idp); - - print '
'; - - // Ref - print ''; - - // Ref client - print ''; - print ''; - - $rowspan=9; - - // Société - print ''; - print ''; - - // Ligne info remises tiers - print ''; - - // Dates - print ''; - - if ($conf->projet->enabled) $rowspan++; - if ($conf->global->PROPAL_ADD_SHIPPING_DATE) $rowspan++; - if ($conf->global->PROPAL_ADD_DELIVERY_ADDRESS) $rowspan++; - - // Notes - print ''; - print ''; - - // Date fin propal - print ''; - print ''; - print ''; - - - // date de livraison (conditonné sur PROPAL_ADD_SHIPPING_DATE car carac à - // gérer par les commandes et non les propal - if ($conf->global->PROPAL_ADD_SHIPPING_DATE) - { - print ''; - print ''; - } - - // adresse de livraison - if ($conf->global->PROPAL_ADD_DELIVERY_ADDRESS) - { - print ''; - } - - // Conditions et modes de réglement - print ''; - print ''; - - // Mode paiement - print ''; - print ''; - - // Destinataire - $langs->load('mails'); - print ''; - print ''; - - // Projet - if ($conf->projet->enabled) - { - $langs->load("projects"); - print ''; - $numprojet = $societe->has_projects(); - if (! $numprojet) - { - print ''; - } - else - { - if ($propal->statut == 0 && $user->rights->propale->creer) - { - print ''; - } - else - { - if (!empty($propal->projetidp)) - { - print ''; - } - else { - print ''; - } - } - } - print ''; - } - - // Amount - print ''; - print ''; - print ''; - - print ''; - print ''; - print ''; - print ''; - - // Statut - print ''; - print '
'.$langs->trans('Ref').''.$propal->ref_url.'
'; - print ''; - if ($_GET['action'] != 'refclient' && $propal->brouillon) print ''; - print '
'; - print $langs->trans('RefCustomer').''; - print ''.img_edit($langs->trans('Edit')).'
'; - print '
'; - if ($user->rights->propale->creer && $_GET['action'] == 'refclient') - { - print '
'; - print ''; - print ''; - print ' '; - print '
'; - } - else - { - print $propal->ref_client; - } - print '
'.$langs->trans('Company').''.$societe->getNomUrl(1).'
'.$langs->trans('Discounts').''; - if ($societe->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$societe->remise_client); - else print $langs->trans("CompanyHasNoRelativeDiscount"); - $absolute_discount=$societe->getCurrentDiscount(); - 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); - } - else print $langs->trans("CompanyHasNoAbsoluteDiscount").'.'; - print '
'.$langs->trans('Date').''; - print dolibarr_print_date($propal->date,'%a %d %B %Y'); - print ''.$langs->trans('NotePublic').' :
'. nl2br($propal->note_public).'
'; - print ''; - if ($_GET['action'] != 'editecheance' && $propal->brouillon) print ''; - print '
'; - print $langs->trans('DateEndPropal'); - print 'id.'">'.img_edit($langs->trans('SetConditions'),1).'
'; - print '
'; - if ($propal->brouillon && $_GET['action'] == 'editecheance') - { - print '
'; - print ''; - $html->select_date($propal->fin_validite,'ech','','','',"editecheance"); - print ''; - print '
'; - } - else - { - if ($propal->fin_validite) - { - print dolibarr_print_date($propal->fin_validite,'%a %d %B %Y'); - if ($propal->statut == 1 && $propal->fin_validite < (time() - $conf->propal->cloture->warning_delay)) print img_warning($langs->trans("Late")); - } - else - { - print ' '; - } - } - print '
'; - print ''; - if ($_GET['action'] != 'editdate_livraison' && $propal->brouillon) print ''; - print '
'; - print $langs->trans('DateDelivery'); - print 'id.'">'.img_edit($langs->trans('SetDateLivraison'),1).'
'; - print '
'; - if ($_GET['action'] == 'editdate_livraison') - { - print '
'; - print ''; - $html->select_date($propal->date_livraison,'liv_','','','',"editdate_livraison"); - print ''; - print '
'; - } - else - { - print dolibarr_print_date($propal->date_livraison,'%a %d %B %Y'); - } - print '
'; - print ''; - - if ($_GET['action'] != 'editdelivery_adress' && $propal->brouillon) print ''; - print '
'; - print $langs->trans('DeliveryAddress'); - print 'socidp.'&propalid='.$propal->id.'">'.img_edit($langs->trans('SetDeliveryAddress'),1).'
'; - print '
'; - - if ($_GET['action'] == 'editdelivery_adress') - { - $html->form_adresse_livraison($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->adresse_livraison_id,$_GET['socidp'],'adresse_livraison_id','propal',$propal->id); - } - else - { - $html->form_adresse_livraison($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->adresse_livraison_id,$_GET['socidp'],'none','propal',$propal->id); - } - print '
'; - print ''; - if ($_GET['action'] != 'editconditions' && $propal->brouillon) print ''; - print '
'; - print $langs->trans('PaymentConditionsShort'); - print 'id.'">'.img_edit($langs->trans('SetConditions'),1).'
'; - print '
'; - if ($_GET['action'] == 'editconditions') - { - $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->cond_reglement_id,'cond_reglement_id'); - } - else - { - $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->cond_reglement_id,'none'); - } - print '
'; - print ''; - if ($_GET['action'] != 'editmode' && $propal->brouillon) print ''; - print '
'; - print $langs->trans('PaymentMode'); - print 'id.'">'.img_edit($langs->trans('SetMode'),1).'
'; - print '
'; - if ($_GET['action'] == 'editmode') - { - $html->form_modes_reglement($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->mode_reglement_id,'mode_reglement_id'); - } - else - { - $html->form_modes_reglement($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->mode_reglement_id,'none'); - } - 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 '
'.$langs->trans('Project').''; - print $langs->trans("NoProject").''; - print 'id.'&action=create>'.$langs->trans('AddProject').''; - print ''; - print '
'; - print ''; - $form->select_projects($societe->id, $propal->projetidp, 'projetidp'); - print '
'; - print ''; - print ''; - print ''; - $proj = new Project($db); - $proj->fetch($propal->projetidp); - print ''; - print $proj->title; - print ''; - print ' 
'.$langs->trans('AmountHT').''.price($propal->price).''.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans('AmountVAT').''.price($propal->total_tva).''.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans('AmountTTC').''.price($propal->total_ttc).''.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans('Status').''.$propal->getLibStatut(4).'

'; - - /* - * Lignes de propale - */ - print ''; - - $sql = 'SELECT pt.rowid, pt.description, pt.price, pt.fk_product, pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice,'; - $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'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pt.fk_product=p.rowid'; - $sql.= ' WHERE pt.fk_propal = '.$propal->id; - $sql.= ' ORDER BY pt.rang ASC, pt.rowid'; - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - $i = 0; $total = 0; - - if ($num) - { - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - } - $var=true; - while ($i < $num) - { - $objp = $db->fetch_object($resql); - $var=!$var; - - // Ligne en mode visu - if ($_GET['action'] != 'editline' || $_GET['ligne'] != $objp->rowid) - { - print ''; - if ($objp->fk_product > 0) - { - print ''; - } - else - { - print '\n"; - } - print ''; - print '\n"; - print ''; - if ($objp->remise_percent > 0) - { - print '\n"; - } - else - { - print ''; - } - print '\n"; - - // Icone d'edition et suppression - if ($propal->statut == 0 && $user->rights->propale->creer) - { - print ''; - if ($conf->global->PRODUIT_CONFIRM_DELETE_LINE) - { - print ''; - print ''; - } - else - { - print ''; - } - - print ''; - } - - // Ligne en mode update - if ($propal->statut == 0 && $_GET["action"] == 'editline' && $user->rights->propale->creer && $_GET["ligne"] == $objp->rowid) - { - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print '' . "\n"; - /* - if ($conf->service->enabled) - { - print ""; - print ''; - print '' . "\n"; - } - */ - print "\n"; - } - - $total = $total + ($objp->qty * $objp->price); - $i++; - } - - $db->free($resql); - } - else - { - dolibarr_print_error($db); - } - - - /* - * Lignes de remise - */ - - // Réductions relatives (Remises-Ristournes-Rabbais) - /* Une réduction doit s'appliquer obligatoirement sur des lignes de factures - $var=!$var; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - if ($_GET['action'] != 'editrelativediscount') - { - if ($propal->brouillon && $user->rights->propale->creer) - { - print ''; - } - else - { - print ''; - } - if ($propal->brouillon && $user->rights->propale->creer && $propal->remise_percent) - { - print ''; - } - else - { - print ''; - } - print ''; - } - else - { - print ''; - } - print ''; - print ''; - */ - - // Réductions absolues (Remises-Ristournes-Rabbais) - /* Les remises absolues doivent s'appliquer par ajout de lignes spécialisées - $var=!$var; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - if ($_GET['action'] != 'editabsolutediscount') - { - if ($propal->brouillon && $user->rights->propale->creer) - { - print ''; - } - else - { - print ''; - } - if ($propal->brouillon && $user->rights->propale->creer && $propal->remise_absolue) - { - print ''; - } - else - { - print ''; - } - print ''; - } - else - { - print ''; - } - print ''; - print ''; - */ - - /* - * Ajouter une ligne - */ - if ($propal->statut == 0 && $user->rights->propale->creer && $_GET["action"] <> 'editline') - { - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - - // Ajout produit produits/services personalisés - print ''; - print ''; - print ''; - - $var=true; - - print '\n"; - print ''; - print '\n"; - print ''; - print ''; - print ''; - print ''; - print ''; - - print ''; - - // Ajout de produits/services prédéfinis - if ($conf->produit->enabled) - { - print ''; - print ''; - print ''; - - $var=!$var; - - print ''; - print ''; - print ''; - print ''; - print ''; - - print ''."\n"; - - print ''; - } - } - - print '
'.$langs->trans('Description').''.$langs->trans('VAT').''.$langs->trans('PriceUHT').''.$langs->trans('Qty').''.$langs->trans('ReductionShort').''.$langs->trans('AmountHT').'   
'; - 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)); - - if ($conf->global->PROP_ADD_PROD_DESC && !$conf->global->PRODUIT_CHANGE_PROD_DESC) - { - print '
'.nl2br(stripslashes($objp->product_desc)); - } - - 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 ($objp->description && $objp->description!=$objp->product)?'
'.stripslashes(nl2br($objp->description)):''; - print '
'.stripslashes(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).')'; - } - print "'.$objp->tva_tx.'%'.price($objp->subprice)."'.$objp->qty.''.$objp->remise_percent."% '.price($objp->subprice*$objp->qty*(100-$objp->remise_percent)/100)."rowid.'">'; - print img_edit(); - print 'rowid.'">'; - } - else - { - print 'rowid.'">'; - } - print img_delete(); - print ''; - if ($i > 0) - { - print 'rowid.'">'; - print img_up(); - print ''; - } - if ($i < $num-1) - { - print 'rowid.'">'; - print img_down(); - print ''; - } - print ' 
'; - if ($objp->fk_product > 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.''; - print ' - '.stripslashes(nl2br($objp->product)); - print '
'; - } - print '
'; - if($societe->tva_assuj == "0") - print '0'; - else - print $html->select_tva("tva_tx",$objp->tva_tx,$mysoc,$societe); - print '%'; - print '
Si produit de type service à durée limitée: Du '; - print $html->select_date($objp->date_start,"date_start",0,0,$objp->date_start?0:1); - print ' au '; - print $html->select_date($objp->date_end,"date_end",0,0,$objp->date_end?0:1); - print '
'; - print $langs->trans('CustomerRelativeDiscount'); - if ($propal->brouillon) print ' ('.($soc->remise_client?$langs->trans("CompanyHasRelativeDiscount",$soc->remise_client):$langs->trans("CompanyHasNoRelativeDiscount")).')'; - print '   '; - if ($_GET['action'] == 'editrelativediscount') - { - print '%'; - } - else - { - print $propal->remise_percent?$propal->remise_percent.'%':' '; - } - print ''; - if ($_GET['action'] != 'editrelativediscount') print $propal->remise_percent?'-'.price($propal->remise_percent*$total/100):$langs->trans("DiscountNone"); - else print ' '; - print 'id.'">'.img_edit($langs->trans('SetRelativeDiscount'),1).' rowid.'">'; - print img_delete(); - print '  
'; - print $langs->trans('CustomerAbsoluteDiscount'); - if ($propal->brouillon) print ' ('.($avoir_en_cours?$langs->trans("CompanyHasAbsoluteDiscount",$avoir_en_cours,$langs->trans("Currency".$conf->monnaie)):$langs->trans("CompanyHasNoAbsoluteDiscount")).')'; - print '    '; - if ($_GET['action'] == 'editabsolutediscount') - { - print '-'; - } - else - { - print $propal->remise_absolue?'-'.price($propal->remise_absolue):$langs->trans("DiscountNone"); - } - print 'id.'">'.img_edit($langs->trans('SetAbsoluteDiscount'),1).' rowid.'">'; - print img_delete(); - print '  
'.$langs->trans('Description').''.$langs->trans('VAT').''.$langs->trans('PriceUHT').''.$langs->trans('Qty').''.$langs->trans('ReductionShort').'    
'; - if($societe->tva_assuj == "0") - { - print '0'; - } - else - { - $html->select_tva('np_tva_tx', $conf->defaulttx, $mysoc, $societe); - } - print "%
'; - // multiprix - if($conf->global->PRODUIT_MULTIPRICES == 1) - { - $html->select_produits('','idprod','',$conf->produit->limit_size,$societe->price_level); - } - else - { - $html->select_produits('','idprod','',$conf->produit->limit_size); - } - if (! $conf->use_ajax) print '
'; - print ''; - print '
 %'; - print '
'; + print ''; + print ''.$langs->trans('Description').''; + print ''.$langs->trans('VAT').''; + print ''.$langs->trans('PriceUHT').''; + print ''.$langs->trans('Qty').''; + print ''.$langs->trans('ReductionShort').''; + print ''.$langs->trans('AmountHT').''; + print ' '; + print ' '; + print ' '; + print "\n"; } + $var=true; + while ($i < $num) + { + $objp = $db->fetch_object($resql); + $var=!$var; + + // Ligne en mode visu + if ($_GET['action'] != 'editline' || $_GET['ligne'] != $objp->rowid) + { + print ''; + if ($objp->fk_product > 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.''; + print ' - '.nl2br(stripslashes($objp->product)); + + if ($conf->global->PROP_ADD_PROD_DESC && !$conf->global->PRODUIT_CHANGE_PROD_DESC) + { + print '
'.nl2br(stripslashes($objp->product_desc)); + } + + 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 ($objp->description && $objp->description!=$objp->product)?'
'.stripslashes(nl2br($objp->description)):''; + print ''; + } + else + { + print ''.stripslashes(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).')'; + } + print "\n"; + } + print ''.$objp->tva_tx.'%'; + print ''.price($objp->subprice)."\n"; + print ''.$objp->qty.''; + if ($objp->remise_percent > 0) + { + print ''.$objp->remise_percent."%\n"; + } + else + { + print ' '; + } + print ''.price($objp->subprice*$objp->qty*(100-$objp->remise_percent)/100)."\n"; + + // Icone d'edition et suppression + if ($propal->statut == 0 && $user->rights->propale->creer) + { + print 'rowid.'">'; + print img_edit(); + print ''; + if ($conf->global->PRODUIT_CONFIRM_DELETE_LINE) + { + print 'rowid.'">'; + } + else + { + print 'rowid.'">'; + } + print img_delete(); + print ''; + print ''; + if ($i > 0) + { + print 'rowid.'">'; + print img_up(); + print ''; + } + if ($i < $num-1) + { + print 'rowid.'">'; + print img_down(); + print ''; + } + print ''; + } + else + { + print ' '; + } + + print ''; + } + + // Ligne en mode update + if ($propal->statut == 0 && $_GET["action"] == 'editline' && $user->rights->propale->creer && $_GET["ligne"] == $objp->rowid) + { + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + if ($objp->fk_product > 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.''; + print ' - '.stripslashes(nl2br($objp->product)); + 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 '
'; + print '' . "\n"; + /* + if ($conf->service->enabled) + { + print ""; + print 'Si produit de type service à durée limitée: Du '; + print $html->select_date($objp->date_start,"date_start",0,0,$objp->date_start?0:1); + print ' au '; + print $html->select_date($objp->date_end,"date_end",0,0,$objp->date_end?0:1); + print ''; + print '' . "\n"; + } + */ + print "
\n"; + } + + $total = $total + ($objp->qty * $objp->price); + $i++; + } + + $db->free($resql); } else { dolibarr_print_error($db); } + + /* + * Lignes de remise + */ + + // Réductions relatives (Remises-Ristournes-Rabbais) + /* Une réduction doit s'appliquer obligatoirement sur des lignes de factures + $var=!$var; + print '
'; + print ''; + print ''; + print ''; + print $langs->trans('CustomerRelativeDiscount'); + if ($propal->brouillon) print ' ('.($soc->remise_client?$langs->trans("CompanyHasRelativeDiscount",$soc->remise_client):$langs->trans("CompanyHasNoRelativeDiscount")).')'; + print ''; + print ' '; + print ' '; + print ' '; + print ''; + if ($_GET['action'] == 'editrelativediscount') + { + print '%'; + } + else + { + print $propal->remise_percent?$propal->remise_percent.'%':' '; + } + print ''; + print ''; + if ($_GET['action'] != 'editrelativediscount') print $propal->remise_percent?'-'.price($propal->remise_percent*$total/100):$langs->trans("DiscountNone"); + else print ' '; + print ''; + if ($_GET['action'] != 'editrelativediscount') + { + if ($propal->brouillon && $user->rights->propale->creer) + { + print 'id.'">'.img_edit($langs->trans('SetRelativeDiscount'),1).''; + } + else + { + print ' '; + } + if ($propal->brouillon && $user->rights->propale->creer && $propal->remise_percent) + { + print 'rowid.'">'; + print img_delete(); + print ''; + } + else + { + print ' '; + } + print ' '; + } + else + { + print ''; + } + print ''; + print '
'; + */ + + // Réductions absolues (Remises-Ristournes-Rabbais) + /* Les remises absolues doivent s'appliquer par ajout de lignes spécialisées + $var=!$var; + print '
'; + print ''; + print ''; + print ''; + print $langs->trans('CustomerAbsoluteDiscount'); + if ($propal->brouillon) print ' ('.($avoir_en_cours?$langs->trans("CompanyHasAbsoluteDiscount",$avoir_en_cours,$langs->trans("Currency".$conf->monnaie)):$langs->trans("CompanyHasNoAbsoluteDiscount")).')'; + print ''; + print ' '; + print ' '; + print ' '; + print ' '; + print ''; + if ($_GET['action'] == 'editabsolutediscount') + { + print '-'; + } + else + { + print $propal->remise_absolue?'-'.price($propal->remise_absolue):$langs->trans("DiscountNone"); + } + print ''; + if ($_GET['action'] != 'editabsolutediscount') + { + if ($propal->brouillon && $user->rights->propale->creer) + { + print 'id.'">'.img_edit($langs->trans('SetAbsoluteDiscount'),1).''; + } + else + { + print ' '; + } + if ($propal->brouillon && $user->rights->propale->creer && $propal->remise_absolue) + { + print 'rowid.'">'; + print img_delete(); + print ''; + } + else + { + print ' '; + } + print ' '; + } + else + { + print ''; + } + print ''; + print '
'; + */ + + /* + * Ajouter une ligne + */ + if ($propal->statut == 0 && $user->rights->propale->creer && $_GET["action"] <> 'editline') + { + print ''; + print ''.$langs->trans('Description').''; + print ''.$langs->trans('VAT').''; + print ''.$langs->trans('PriceUHT').''; + print ''.$langs->trans('Qty').''; + print ''.$langs->trans('ReductionShort').''; + print ' '; + print ' '; + print ' '; + print ' '; + print "\n"; + + // Ajout produit produits/services personalisés + print '
'; + print ''; + print ''; + + $var=true; + + print '\n"; + print ''; + print ''; + if($societe->tva_assuj == "0") + { + print '0'; + } + else + { + $html->select_tva('np_tva_tx', $conf->defaulttx, $mysoc, $societe); + } + print "\n"; + print ''; + print ''; + print '%'; + print ''; + print ''; + + print '
'; + + // Ajout de produits/services prédéfinis + if ($conf->produit->enabled) + { + print '
'; + print ''; + print ''; + + $var=!$var; + + print ''; + print ''; + // multiprix + if($conf->global->PRODUIT_MULTIPRICES == 1) + { + $html->select_produits('','idprod','',$conf->produit->limit_size,$societe->price_level); + } + else + { + $html->select_produits('','idprod','',$conf->produit->limit_size); + } + if (! $conf->use_ajax) print '
'; + print ''; + print ''; + print ' '; + print ''; + print '%'; + + print ''; + print ''."\n"; + + print '
'; + } + } + + print ''; + print ''; print "\n"; @@ -1274,6 +1253,7 @@ if ($_GET['propalid'] > 0) print ''.$langs->trans("CloseAs").''; print ''; print ''; diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php index 927133cc80d..6974aa67dcd 100644 --- a/htdocs/commande/commande.class.php +++ b/htdocs/commande/commande.class.php @@ -2158,20 +2158,21 @@ class Commande class CommandeLigne { - // From llx_propaldet - var $qty; - var $tva_tx; - var $subprice; - var $remise_percent; - var $price; - var $product_id; - var $desc; // Description ligne - var $coef; + // From llx_commandedet + var $qty; + var $tva_tx; + var $subprice; + var $remise_percent; + var $price; + var $product_id; // Id produit prédéfini + var $desc; // Description ligne + var $coef; - // From llx_product - var $libelle; // Label produit - var $product_desc; // Description produit - var $ref; + // From llx_product + var $libelle; // Label produit + var $product_desc; // Description produit + var $ref; // Reference produit + function CommandeLigne() { diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index ab3b4549973..470bc069c46 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -242,12 +242,11 @@ if ($_POST['action'] == 'add') { for ($i = 0 ; $i < sizeof($prop->lignes) ; $i++) { - $liblignefac=($prop->lignes[$i]->desc?$prop->lignes[$i]->desc:$prop->lignes[$i]->libelle); + $desc=($prop->lignes[$i]->desc?$prop->lignes[$i]->desc:$prop->lignes[$i]->libelle); $result = $facture->addline( $facid, - addslashes($liblignefac), - $prop->lignes[$i]->desc, + $desc, $prop->lignes[$i]->subprice, $prop->lignes[$i]->qty, $prop->lignes[$i]->tva_tx, @@ -281,10 +280,11 @@ if ($_POST['action'] == 'add') $lines = $comm->fetch_lignes(); for ($i = 0 ; $i < sizeof($lines) ; $i++) { + $desc=($lignes[$i]->description ? $lignes[$i]->description : $lignes[$i]->libelle); + $result = $facture->addline( $facid, - addslashes($lines[$i]->description), - $lines[$i]->desc, + $desc, $lines[$i]->subprice, $lines[$i]->qty, $lines[$i]->tva_tx, @@ -319,7 +319,7 @@ if ($_POST['action'] == 'add') for ($i = 0 ; $i < sizeof($lines) ; $i++) { - $liblignefac=($contrat->lignes[$i]->desc?$contrat->lignes[$i]->desc:$contrat->lignes[$i]->libelle); + $desc=($contrat->lignes[$i]->desc?$contrat->lignes[$i]->desc:$contrat->lignes[$i]->libelle); // Plage de dates $date_start=$contrat->lignes[$i]->date_debut_prevue; @@ -329,8 +329,7 @@ if ($_POST['action'] == 'add') $result = $facture->addline( $facid, - addslashes($liblignefac), - '', + $desc, $lines[$i]->subprice, $lines[$i]->qty, $lines[$i]->tva_tx, @@ -367,6 +366,9 @@ if (($_POST['action'] == 'addligne' || $_POST['action'] == 'addligne_predef') && { $fac = new Facture($db); $fac->fetch($_POST['facid']); + $soc = new Societe($db); + $soc->fetch($fac->socidp); + $datestart=''; $dateend=''; // Si ajout champ produit libre @@ -393,13 +395,42 @@ if (($_POST['action'] == 'addligne' || $_POST['action'] == 'addligne_predef') && $dateend=$_POST['date_end_predefyear'].'-'.$_POST['date_end_predefmonth'].'-'.$_POST['date_end_predefday']; } } + + // Ecrase $pu par celui du produit + // Ecrase $desc par celui du produit + // Ecrase $txtva par celui du produit + if ($_POST['idprod']) + { + $prod = new Product($db, $_POST['idprod']); + $prod->fetch($_POST['idprod']); + // multiprix + if ($conf->global->PRODUIT_MULTIPRICES == 1) + { + $pu = $prod->multiprices[$soc->price_level]; + } + else + { + $pu=$prod->price; + } + $desc=$_POST['desc']; + if (! $desc) $desc = $prod->description; + if ($conf->global->PRODUIT_CHANGE_PROD_DESC) $prod->description; + $tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx); + } + else + { + $pu=$_POST['pu']; + $tva_tx=$_POST['tva_tx']; + $desc=$_POST['desc']; + } + + // Insere ligne $result = $fac->addline( $_POST['facid'], - $_POST['desc'], - $_POST['product_desc'], - $_POST['pu'], + $desc, + $pu, $_POST['qty'], - $_POST['tva_tx'], + $tva_tx, $_POST['idprod'], $_POST['remise_percent'], $datestart, @@ -1933,7 +1964,7 @@ else $html->select_produits('','idprod','',$conf->produit->limit_size,$soc->price_level); else $html->select_produits('','idprod','',$conf->produit->limit_size); - print '
'; + if (! $conf->use_ajax) print '
'; print ''; print ' '; print ''; diff --git a/htdocs/compta/propal.php b/htdocs/compta/propal.php index f535d5daf6b..cc2c0187f29 100644 --- a/htdocs/compta/propal.php +++ b/htdocs/compta/propal.php @@ -118,430 +118,425 @@ $html = new Form($db); */ if ($_GET["propalid"] > 0) { - if ($mesg) print "$mesg
"; + if ($mesg) print "$mesg
"; + + $propal = new Propal($db); + $propal->fetch($_GET['propalid']); + + $societe = new Societe($db); + $societe->fetch($propal->soc_id); - $propal = new Propal($db); - $propal->fetch($_GET["propalid"]); - $head = propal_prepare_head($propal); dolibarr_fiche_head($head, 'compta', $langs->trans('Proposal')); - + /* * Fiche propal * */ - $sql = 'SELECT s.nom, s.idp, p.price, p.fk_projet, p.remise, p.tva, p.total, p.ref,'.$db->pdate('p.datep').' as dp, c.id as statut, c.label as lst, p.note,'; - $sql.= ' x.firstname, x.name, x.fax, x.phone, x.email, p.fk_user_author, p.fk_user_valid, p.fk_user_cloture, p.datec, p.date_valid, p.date_cloture, p.fk_cond_reglement, p.fk_mode_reglement'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'propal as p, '.MAIN_DB_PREFIX.'c_propalst as c, '.MAIN_DB_PREFIX.'socpeople as x'; - $sql.= ' WHERE p.fk_soc = s.idp AND p.fk_statut = c.id AND x.idp = p.fk_soc_contact AND p.rowid = '.$propal->id; - if ($socidp) $sql .= ' AND s.idp = '.$socidp; + print ''; + + // Ref + print ''; + + // Ref client + print ''; + print ''; + + $rowspan=8; - $resql = $db->query($sql); - if ($resql) + // Société + print ''; + + // Ligne info remises tiers + print ''; + + // Dates + print ''; + + if ($conf->projet->enabled) $rowspan++; + + // Note + print ''; + print ''; + + // Date fin propal + print ''; + print ''; + print ''; + + // Conditions et modes de réglement + print ''; + + // Mode de paiement + print ''; + print ''; + + // Destinataire +/* Remplacé par contacts de propal + $langs->load('mails'); + print ''; + print ''; + + if ($propal->statut == 0 && $user->rights->propale->creer) + { + print ''; + } + else + { + if (!empty($propal->contactid)) { - $obj = $db->fetch_object($resql); - - $societe = new Societe($db); - $societe->fetch($obj->idp); - - print '
'.$langs->trans('Ref').''.$propal->ref_url.'
'; + print ''; + if ($_GET['action'] != 'refclient' && $propal->brouillon) print ''; + print '
'; + print $langs->trans('RefCustomer').''; + print ''.img_edit($langs->trans('Edit')).'
'; + print '
'; + print $propal->ref_client; + print '
'.$langs->trans('Company').''.$societe->getNomUrl(1).'
'.$langs->trans('Discounts').''; + if ($societe->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$societe->remise_client); + else print $langs->trans("CompanyHasNoRelativeDiscount"); + $absolute_discount=$societe->getCurrentDiscount(); + print '. '; + if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie)); + else print $langs->trans("CompanyHasNoAbsoluteDiscount"); + print '.'; + print '
'.$langs->trans('Date').''; + print dolibarr_print_date($propal->date,'%a %d %B %Y'); + print ''.$langs->trans('NotePublic').' :
'. nl2br($propal->note_public).'
'.$langs->trans('DateEndPropal').''; + if ($propal->fin_validite) { - if ($db->num_rows($resql)) + print dolibarr_print_date($propal->fin_validite,'%a %d %B %Y'); + if ($propal->statut == 1 && $propal->fin_validite < (time() - $conf->propal->cloture->warning_delay)) print img_warning($langs->trans("Late")); + } + else + { + print $langs->trans("Unknown"); + } + print '
'; + print ''; + if ($_GET['action'] != 'editconditions' && $propal->brouillon) print ''; + print '
'; + print $langs->trans('PaymentConditionsShort'); + print 'id.'">'.img_edit($langs->trans('SetConditions'),1).'
'; + print '
'; + if ($_GET['action'] == 'editconditions') + { + $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->cond_reglement_id,'cond_reglement_id'); + } + else + { + $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->cond_reglement_id,'none'); + } + print '
'; + print ''; + if ($_GET['action'] != 'editmode' && $propal->brouillon) print ''; + print '
'; + print $langs->trans('PaymentMode'); + print 'id.'">'.img_edit($langs->trans('SetMode'),1).'
'; + print '
'; + if ($_GET['action'] == 'editmode') + { + $html->form_modes_reglement($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->mode_reglement_id,'mode_reglement_id'); + } + else + { + $html->form_modes_reglement($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->mode_reglement_id,'none'); + } + print '
'.$langs->trans('MailTo').''; + $html->form_contacts($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$societe,$propal->contactid,'none'); + print '
'; - - // Ref - print ''; - - $rowspan=9; - - // Société - print ''; - - // Ligne info remises tiers - print ''; - - // Dates - print ''; - - if ($conf->projet->enabled) $rowspan++; - - // Note - print ''; - print ''; - - // Date fin propal - print ''; - print ''; + } + } +*/ + + // Projet + if ($conf->projet->enabled) + { + $langs->load("projects"); + print ''; + $numprojet = $societe->has_projects(); + if (! $numprojet) + { + print ''; - print ''; - - // Conditions et modes de réglement - print ''; - - // Mode de paiement - print ''; - print ''; - - // Destinataire - $langs->load('mails'); - print ''; - print ''; - + } + else + { if ($propal->statut == 0 && $user->rights->propale->creer) { print ''; } else { - if (!empty($propal->contactid)) + if (!empty($propal->projetidp)) { print ''; } else { print ''; } } - - // Projet - if ($conf->projet->enabled) + } + print ''; + } + + // Amount + print ''; + print ''; + print ''; + + print ''; + print ''; + print ''; + print ''; + + + // Statut + print ''; + print '
'.$langs->trans('Ref').''.$propal->ref_url.'
'.$langs->trans('Company').''.$societe->getNomUrl(1).'
'.$langs->trans('Discounts').''; - if ($societe->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$societe->remise_client); - else print $langs->trans("CompanyHasNoRelativeDiscount"); - $absolute_discount=$societe->getCurrentDiscount(); - print '. '; - if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie)); - else print $langs->trans("CompanyHasNoAbsoluteDiscount"); - print '.'; - print '
'.$langs->trans('Date').''; - print dolibarr_print_date($propal->date,'%a %d %B %Y'); + print ''; + $html->form_contacts($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$societe,$propal->contactid,'none'); print ''.$langs->trans('NotePublic').' :
'. nl2br($propal->note_public).'
'.$langs->trans('DateEndPropal').''; - if ($propal->fin_validite) - { - print dolibarr_print_date($propal->fin_validite,'%a %d %B %Y'); - if ($propal->statut == 1 && $propal->fin_validite < (time() - $conf->propal->cloture->warning_delay)) print img_warning($langs->trans("Late")); - } - else - { - print $langs->trans("Unknown"); - } + } + else { + print ' 
'.$langs->trans('Project').''; + print $langs->trans("NoProject").''; + print 'id.'&action=create>'.$langs->trans('AddProject').''; print '
'; - print ''; - if ($_GET['action'] != 'editconditions' && $propal->brouillon) print ''; - print '
'; - print $langs->trans('PaymentConditionsShort'); - print 'id.'">'.img_edit($langs->trans('SetConditions'),1).'
'; - print '
'; - if ($_GET['action'] == 'editconditions') - { - $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->cond_reglement_id,'cond_reglement_id'); - } - else - { - $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->cond_reglement_id,'none'); - } - print '
'; - print ''; - if ($_GET['action'] != 'editmode' && $propal->brouillon) print ''; - print '
'; - print $langs->trans('PaymentMode'); - print 'id.'">'.img_edit($langs->trans('SetMode'),1).'
'; - print '
'; - if ($_GET['action'] == 'editmode') - { - $html->form_modes_reglement($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->mode_reglement_id,'mode_reglement_id'); - } - else - { - $html->form_modes_reglement($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->mode_reglement_id,'none'); - } - print '
'.$langs->trans('MailTo').''; - $html->form_contacts($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$societe,$propal->contactid,'none'); + $html->select_projects($societe->id, $propal->projetidp, 'projetidp'); print ''; - $html->form_contacts($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$societe,$propal->contactid,'none'); + $proj = new Project($db); + $proj->fetch($propal->projetidp); + print ''; + print $proj->title; + print ''; print ' 
'.$langs->trans('AmountHT').''.price($propal->price).''.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans('AmountVAT').''.price($propal->total_tva).''.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans('AmountTTC').''.price($propal->total_ttc).''.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans('Status').''.$propal->getLibStatut(4).'

'; + + /* + * Lignes de propale + * + */ + $sql = 'SELECT pt.rowid, pt.description, pt.price, pt.fk_product, pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice, p.label as product, p.ref, p.fk_product_type, p.rowid as prodid'; + $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 = '.$propal->id; + $sql .= ' ORDER BY pt.rowid ASC'; + $resql = $db->query($sql); + if ($resql) + { + $num_lignes = $db->num_rows($resql); + $i = 0; + $total = 0; + + print ''; + if ($num_lignes) + { + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + } + $var=true; + while ($i < $num_lignes) + { + $objp = $db->fetch_object($resql); + $var=!$var; + if ($_GET['action'] != 'editline' || $_GET['rowid'] != $objp->rowid) { - $langs->load("projects"); - print ''; - $numprojet = $societe->has_projects(); - if (! $numprojet) + print ''; + if ($objp->fk_product > 0) { - print ''; } else { - if ($propal->statut == 0 && $user->rights->propale->creer) + print ''; + print ' (Du '.dolibarr_print_date($objp->date_start).' au '.dolibarr_print_date($objp->date_end).')'; } - else + if ($objp->date_start && ! $objp->date_end) { - if (!empty($propal->projetidp)) - { - print ''; - } - else { - print ''; - } + 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 ''; + print '\n"; + print ''; + if ($objp->remise_percent > 0) + { + print '\n"; + } + else + { + print ''; + } + print '\n"; + + print ''; + print ''; } - - // Amount - print ''; - print ''; - print ''; - - print ''; - print ''; - print ''; - print ''; - // Statut - print ''; - print '
'.$langs->trans('Description').''.$langs->trans('VAT').''.$langs->trans('PriceUHT').''.$langs->trans('Qty').''.$langs->trans('Discount').''.$langs->trans('AmountHT').'   
'.$langs->trans('Project').'
'; - print $langs->trans("NoProject").''; - print 'id.'&action=create>'.$langs->trans('AddProject').''; + 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)); + 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 ($objp->description && $objp->description!=$objp->product)?'
'.stripslashes(nl2br($objp->description)):''; print '
'.stripslashes(nl2br($objp->description)); + if ($objp->date_start && $objp->date_end) { - print ''; - $html->select_projects($societe->id, $propal->projetidp, 'projetidp'); - print ''; - $proj = new Project($db); - $proj->fetch($propal->projetidp); - print ''; - print $proj->title; - print ''; - print ' '.$objp->tva_tx.'%'.price($objp->subprice)."'.$objp->qty.''.$objp->remise_percent."% '.price($objp->subprice*$objp->qty*(100-$objp->remise_percent)/100)." 
'.$langs->trans('AmountHT').''.price($propal->price).''.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans('AmountVAT').''.price($propal->total_tva).''.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans('AmountTTC').''.price($propal->total_ttc).''.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans('Status').''.$propal->getLibStatut(4).'

'; - - /* - * Lignes de propale - * - */ - $sql = 'SELECT pt.rowid, pt.description, pt.price, pt.fk_product, pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice, p.label as product, p.ref, p.fk_product_type, p.rowid as prodid'; - $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 = '.$propal->id; - $sql .= ' ORDER BY pt.rowid ASC'; - $resql = $db->query($sql); - if ($resql) - { - $num_lignes = $db->num_rows($resql); - $i = 0; - $total = 0; - - print ''; - if ($num_lignes) - { - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - } - $var=true; - while ($i < $num_lignes) - { - $objp = $db->fetch_object($resql); - $var=!$var; - if ($_GET['action'] != 'editline' || $_GET['rowid'] != $objp->rowid) - { - print ''; - if ($objp->fk_product > 0) - { - print ''; - } - else - { - print '\n"; - } - print ''; - print '\n"; - print ''; - if ($objp->remise_percent > 0) - { - print '\n"; - } - else - { - print ''; - } - print '\n"; - - print ''; - - print ''; - } - - - - $total = $total + ($objp->qty * $objp->price); - $i++; - } - $db->free($resql); - } - else - { - dolibarr_print_error($db); - } - - /* - * Lignes de remise - */ - - // Réductions relatives (Remises-Ristournes-Rabbais) -/* Une réduction doit s'appliquer obligatoirement sur des lignes de factures - et non globalement - $var=!$var; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - if ($_GET['action'] != 'editrelativediscount') - { - if ($propal->brouillon && $user->rights->propale->creer) - { - print ''; - } - else - { - print ''; - } - if ($propal->brouillon && $user->rights->propale->creer && $propal->remise_percent) - { - print ''; - } - else - { - print ''; - } - print ''; - } - else - { - print ''; - } - print ''; - print ''; -*/ - // Remise absolue -/* Les remises absolues doivent s'appliquer par ajout de lignes spécialisées - $var=!$var; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - if ($_GET['action'] != 'editabsolutediscount') - { - if ($propal->brouillon && $user->rights->propale->creer) - { - print ''; - } - else - { - print ''; - } - if ($propal->brouillon && $user->rights->propale->creer && $propal->remise_absolue) - { - print ''; - } - else - { - print ''; - } - print ''; - } - else - { - print ''; - } - print ''; - print ''; -*/ - print '
'.$langs->trans('Description').''.$langs->trans('VAT').''.$langs->trans('PriceUHT').''.$langs->trans('Qty').''.$langs->trans('Discount').''.$langs->trans('AmountHT').'   
'; - 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)); - 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 ($objp->description && $objp->description!=$objp->product)?'
'.stripslashes(nl2br($objp->description)):''; - print '
'.stripslashes(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).')'; - } - print "'.$objp->tva_tx.'%'.price($objp->subprice)."'.$objp->qty.''.$objp->remise_percent."% '.price($objp->subprice*$objp->qty*(100-$objp->remise_percent)/100)." 
'; - print $langs->trans('CustomerRelativeDiscount'); - if ($propal->brouillon) print ' ('.($soc->remise_client?$langs->trans("CompanyHasRelativeDiscount",$soc->remise_client):$langs->trans("CompanyHasNoRelativeDiscount")).')'; - print '   '; - if ($_GET['action'] == 'editrelativediscount') - { - print '%'; - } - else - { - print $propal->remise_percent?$propal->remise_percent.'%':' '; - } - print ''; - if ($_GET['action'] != 'editrelativediscount') print $propal->remise_percent?'-'.price($propal->remise_percent*$total/100):$langs->trans("DiscountNone"); - else print ' '; - print 'id.'">'.img_edit($langs->trans('SetRelativeDiscount'),1).' rowid.'">'; - print img_delete(); - print '  
'; - print $langs->trans('CustomerAbsoluteDiscount'); - if ($propal->brouillon) print ' ('.($avoir_en_cours?$langs->trans("CompanyHasAbsoluteDiscount",$avoir_en_cours,$langs->trans("Currency".$conf->monnaie)):$langs->trans("CompanyHasNoAbsoluteDiscount")).')'; - print '    '; - if ($_GET['action'] == 'editabsolutediscount') - { - print '-'; - } - else - { - print $propal->remise_absolue?'-'.price($propal->remise_absolue):$langs->trans("DiscountNone"); - } - print 'id.'">'.img_edit($langs->trans('SetAbsoluteDiscount'),1).' rowid.'">'; - print img_delete(); - print '  
'; - + $total = $total + ($objp->qty * $objp->price); + $i++; } + $db->free($resql); } else { dolibarr_print_error($db); } + + /* + * Lignes de remise + */ + + // Réductions relatives (Remises-Ristournes-Rabbais) +/* Une réduction doit s'appliquer obligatoirement sur des lignes de factures +et non globalement + $var=!$var; + print '
'; + print ''; + print ''; + print ''; + print $langs->trans('CustomerRelativeDiscount'); + if ($propal->brouillon) print ' ('.($soc->remise_client?$langs->trans("CompanyHasRelativeDiscount",$soc->remise_client):$langs->trans("CompanyHasNoRelativeDiscount")).')'; + print ''; + print ' '; + print ' '; + print ' '; + print ''; + if ($_GET['action'] == 'editrelativediscount') + { + print '%'; + } + else + { + print $propal->remise_percent?$propal->remise_percent.'%':' '; + } + print ''; + print ''; + if ($_GET['action'] != 'editrelativediscount') print $propal->remise_percent?'-'.price($propal->remise_percent*$total/100):$langs->trans("DiscountNone"); + else print ' '; + print ''; + if ($_GET['action'] != 'editrelativediscount') + { + if ($propal->brouillon && $user->rights->propale->creer) + { + print 'id.'">'.img_edit($langs->trans('SetRelativeDiscount'),1).''; + } + else + { + print ' '; + } + if ($propal->brouillon && $user->rights->propale->creer && $propal->remise_percent) + { + print 'rowid.'">'; + print img_delete(); + print ''; + } + else + { + print ' '; + } + print ' '; + } + else + { + print ''; + } + print ''; + print '
'; +*/ + + // Remise absolue +/* Les remises absolues doivent s'appliquer par ajout de lignes spécialisées + $var=!$var; + print '
'; + print ''; + print ''; + print ''; + print $langs->trans('CustomerAbsoluteDiscount'); + if ($propal->brouillon) print ' ('.($avoir_en_cours?$langs->trans("CompanyHasAbsoluteDiscount",$avoir_en_cours,$langs->trans("Currency".$conf->monnaie)):$langs->trans("CompanyHasNoAbsoluteDiscount")).')'; + print ''; + print ' '; + print ' '; + print ' '; + print ' '; + print ''; + if ($_GET['action'] == 'editabsolutediscount') + { + print '-'; + } + else + { + print $propal->remise_absolue?'-'.price($propal->remise_absolue):$langs->trans("DiscountNone"); + } + print ''; + if ($_GET['action'] != 'editabsolutediscount') + { + if ($propal->brouillon && $user->rights->propale->creer) + { + print 'id.'">'.img_edit($langs->trans('SetAbsoluteDiscount'),1).''; + } + else + { + print ' '; + } + if ($propal->brouillon && $user->rights->propale->creer && $propal->remise_absolue) + { + print 'rowid.'">'; + print img_delete(); + print ''; + } + else + { + print ' '; + } + print ' '; + } + else + { + print ''; + } + print ''; + print '
'; +*/ + print ''; + print ''; @@ -688,7 +683,7 @@ if ($_GET["propalid"] > 0) */ $sql = 'SELECT id, '.$db->pdate('a.datea'). ' as da, label, note, fk_user_author' ; $sql .= ' FROM '.MAIN_DB_PREFIX.'actioncomm as a'; - $sql .= ' WHERE a.fk_soc = '.$obj->idp.' AND a.propalrowid = '.$propal->id ; + $sql .= ' WHERE a.fk_soc = '.$societe->id.' AND a.propalrowid = '.$propal->id ; $resql = $db->query($sql); if ($resql) { diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index 3c0cab25658..dbf211e284c 100644 --- a/htdocs/facture.class.php +++ b/htdocs/facture.class.php @@ -107,7 +107,7 @@ class Facture */ function create($user) { - global $langs,$conf; + global $langs,$conf,$mysoc; $this->db->begin(); @@ -198,10 +198,7 @@ class Facture $res=$prod->fetch($this->products[$i]); $soc = new Societe($this->db); $soc->fetch($this->socidp); - if($soc->tva_assuj == "0") - $tva_tx ="0"; - else - $tva_tx=$prod->tva_tx; + $tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx); // multiprix if($conf->global->PRODUIT_MULTIPRICES == 1) $price = $prod->multiprices[$soc->price_level]; @@ -239,8 +236,9 @@ class Facture if ($_facrec->lignes[$i]->produit_id) { $prod = new Product($this->db, $_facrec->lignes[$i]->produit_id); - $prod->fetch($_facrec->lignes[$i]->produit_id); + $res=$prod->fetch($_facrec->lignes[$i]->produit_id); } + $tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx); $result_insert = $this->addline( $this->id, @@ -400,7 +398,7 @@ class Facture */ $sql = 'SELECT l.rowid, l.fk_product, l.description, l.price, l.qty, l.tva_taux, l.remise, l.remise_percent, l.subprice,'; $sql.= ' '.$this->db->pdate('l.date_start').' as date_start,'.$this->db->pdate('l.date_end').' as date_end,'; - $sql.= ' l.info_bits, l.total_ht, l.total_ttc,'; + $sql.= ' l.info_bits, l.total_ht, l.total_tva, l.total_ttc,'; $sql.= ' p.label as label, p.description as product_desc'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facturedet as l'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid'; @@ -432,6 +430,7 @@ class Facture $faclig->date_end = $objp->date_end; $faclig->info_bits = $objp->info_bits; $faclig->total_ht = $objp->total_ht; + $faclig->total_tva = $objp->total_tva; $faclig->total_ttc = $objp->total_ttc; $this->lignes[$i] = $faclig; $i++; @@ -996,23 +995,23 @@ class Facture } /** - * \brief Ajoute une ligne de facture (associé à un produit/service prédéfini ou non) - * \param facid id de la facture - * \param desc description de la ligne - * \param product_desc surcharge description produit - * \param pu prix unitaire - * \param qty quantit - * \param txtva taux de tva - * \param fk_product id du produit/service predéfini - * \param remise_percent pourcentage de remise de la ligne - * \param datestart date de debut de validité du service - * \param dateend date de fin de validité du service - * \param ventil code de ventilation comptable - * \remarks Les parametres sont deja censé etre juste et avec valeurs finales a l'appel - * de cette methode. Aussi, pour le taux tva, il doit deja avoir ete défini - * par l'appelant par la methode get_default_tva(societe_vendeuse,societe_acheteuse,taux_produit) - */ - function addline($facid, $desc, $product_desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0, $datestart='', $dateend='', $ventil = 0) + * \brief Ajoute une ligne de facture (associé à un produit/service prédéfini ou non) + * \param facid id de la facture + * \param desc description de la ligne + * \param pu prix unitaire + * \param qty quantité + * \param txtva taux de tva forcé, sinon -1 + * \param fk_product id du produit/service predéfini + * \param remise_percent pourcentage de remise de la ligne + * \param datestart date de debut de validité du service + * \param dateend date de fin de validité du service + * \param ventil code de ventilation comptable + * \remarks Les parametres sont deja censé etre juste et avec valeurs finales a l'appel + * de cette methode. Aussi, pour le taux tva, il doit deja avoir ete défini + * par l'appelant par la methode get_default_tva(societe_vendeuse,societe_acheteuse,taux_produit) + * et le desc doit deja avoir la bonne valeur (a l'appelant de gerer le multilangue) + */ + function addline($facid, $desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0, $datestart='', $dateend='', $ventil = 0) { global $conf; dolibarr_syslog("facture.class.php::addline($facid,$desc,$product_desc,$pu,$qty,$txtva,$fk_product,$remise_percent,$datestart,$dateend,$ventil)"); @@ -1028,19 +1027,6 @@ class Facture if (! $qty) $qty=1; if (! $ventil) $ventil=0; if (! $info_bits) $info_bits=0; - if ($fk_product && ! $pu) - { - $prod = new Product($this->db, $fk_product); - $prod->fetch($fk_product); - $product_desc = $prod->description; - // multiprix - if($conf->global->PRODUIT_MULTIPRICES == 1) - $pu = $prod->multiprices[$soc->price_level]; - else - { - $pu=$prod->price; - } - } $pu = price2num($pu); $txtva=price2num($txtva); @@ -1082,34 +1068,15 @@ class Facture return -1; } - if ($conf->global->PRODUIT_CHANGE_PROD_DESC) - { - if (!$product_desc) - { - $product_desc = $desc; - } - } - // Insertion dans base de la ligne $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facturedet'; $sql.= ' (fk_facture, description, price, qty, tva_taux,'; $sql.= ' fk_product, remise_percent, subprice, remise, date_start, date_end, fk_code_ventilation, rang,'; $sql.= ' info_bits, total_ht, total_tva, total_ttc)'; - if ($conf->global->PRODUIT_CHANGE_PROD_DESC) - { - $sql.= " VALUES ($facid, '".addslashes($product_desc)."',"; - $sql.= "'".price2num($price)."',"; - $sql.= "'".price2num($qty)."',"; - $sql.= "'".price2num($txtva)."',"; - } - else - { - $sql.= " VALUES ($facid, '".addslashes($desc)."',"; - $sql.= "'".price2num($price)."',"; - $sql.= "'".price2num($qty)."',"; - $sql.= "'".price2num($txtva)."',"; - } - + $sql.= " VALUES (".$facid.", '".addslashes($desc)."',"; + $sql.= "'".price2num($price)."',"; + $sql.= "'".price2num($qty)."',"; + $sql.= "'".price2num($txtva)."',"; if ($fk_product) { $sql.= "'$fk_product',"; } else { $sql.='0,'; } $sql.= " '".price2num($remise_percent)."',"; @@ -1265,7 +1232,7 @@ class Facture $err=0; // Lit les lignes detail - $sql = 'SELECT qty, tva_taux, subprice, remise_percent, price, total_ht, total_ttc'; + $sql = 'SELECT qty, tva_taux, subprice, remise_percent, price, total_ht, total_tva, total_ttc'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facturedet'; $sql.= ' WHERE fk_facture = '.$facid; $result = $this->db->query($sql); diff --git a/htdocs/langs/en_US/companies.lang b/htdocs/langs/en_US/companies.lang index c9cc7368409..8be1b641e62 100644 --- a/htdocs/langs/en_US/companies.lang +++ b/htdocs/langs/en_US/companies.lang @@ -89,6 +89,7 @@ Supplier=Supplier CompanyList=Companies' list AddContact=Add contact Contact=Contact +DefaultContact=Default contact AddCompany=Add company DeleteACompany=Delete a company PersonalInformations=Personal data diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index c9319ed0ca6..12edb91a364 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -104,6 +104,7 @@ Family=Family Description=Description Designation=Description Model=Model +DefaultModel=Default model Action=Action About=About WelcomeString=We are %s, and you are connected as user %s diff --git a/htdocs/langs/fr_FR/companies.lang b/htdocs/langs/fr_FR/companies.lang index 72b79a6bbd9..4c6fee2c102 100644 --- a/htdocs/langs/fr_FR/companies.lang +++ b/htdocs/langs/fr_FR/companies.lang @@ -89,6 +89,7 @@ Supplier=Fournisseur CompanyList=Liste des sociétés AddContact=Créer contact Contact=Contact +DefaultContact=Contact par défaut AddCompany=Créer société DeleteACompany=Supprimer une société PersonalInformations=Informations personnelles diff --git a/htdocs/langs/fr_FR/main.lang b/htdocs/langs/fr_FR/main.lang index 2786338e49c..3e4a0264f9d 100644 --- a/htdocs/langs/fr_FR/main.lang +++ b/htdocs/langs/fr_FR/main.lang @@ -104,6 +104,7 @@ Description=Description Designation=Désignation Action=Action Model=Modèle +DefaultModel=Modèle par défaut About=À propos WelcomeString=Nous sommes le %s, et vous êtes connecté(e) en tant que %s Number=Nombre diff --git a/htdocs/lib/functions.inc.php b/htdocs/lib/functions.inc.php index 1802ef57120..065ba484649 100644 --- a/htdocs/lib/functions.inc.php +++ b/htdocs/lib/functions.inc.php @@ -1702,10 +1702,13 @@ function price2num($amount) * \param taux_produit Taux par defaut du produit vendu * \return float Taux de tva de la ligne */ -function get_default_tva($societe_vendeuse='', $societe_acheteuse='', $taux_produit='') +function get_default_tva($societe_vendeuse, $societe_acheteuse, $taux_produit) { - // Si vendeur non assujeti à TVA - if (! $societe_vendeuse->tva_assuj) return 0; + dolibarr_syslog("get_default_tva vendeur_assujeti=$societe_vendeuse->tva_assuj pays_vendeur=$societe_vendeuse->pays_id, pays_acheteur=$societe_acheteuse->pays_id, taux_produit=$taux_produit"); + + // Si vendeur non assujeti à TVA (tva_assuj vaut 0/1 ou franchise/reel) + if (is_numeric($societe_vendeuse->tva_assuj) && ! $societe_vendeuse->tva_assuj) return 0; + if (! is_numeric($societe_vendeuse->tva_assuj) && $societe_vendeuse->tva_assuj=='franchise') return 0; // Si le (pays vendeur = pays acheteur) alors la TVA par défaut=TVA du produit vendu. Fin de règle. if ($societe_vendeuse->pays_id == $societe_acheteuse->pays_id) diff --git a/htdocs/lib/price.lib.php b/htdocs/lib/price.lib.php index d583f0b2c42..f868f45e667 100644 --- a/htdocs/lib/price.lib.php +++ b/htdocs/lib/price.lib.php @@ -33,22 +33,25 @@ /** \brief Permet de calculer les parts total HT, TVA et TTC d'une ligne de - facture, propale ou autre depuis son prix unitaire, quantité et remise ligne. + facture, propale ou autre depuis: + Prix unitaire, quantité, remise_percent_ligne, txtva, remise_percent_global. \param qty \param pu - \param remise_percent + \param remise_percent_ligne \param txtva + \param remise_percent_global \return result[0] total_ht result[1] total_tva result[2] total_ttc */ -function calcul_price_total($qty, $pu, $remise_percent, $txtva) +function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $remise_percent_global=0) { $result=array(); $tot_sans_remise = $pu * $qty; - $tot_avec_remise = $tot_sans_remise - ($tot_sans_remise * $remise_percent / 100); + $tot_avec_remise_ligne = $tot_sans_remise * ( 1 - ($remise_percent_ligne / 100)); + $tot_avec_remise = $tot_avec_remise_ligne * ( 1 - ($remise_percent_global / 100)); $result[0] = round($tot_avec_remise, 2); - $result[2] = round($tot_avec_remise + ($tot_avec_remise * $txtva / 100), 2); + $result[2] = round($tot_avec_remise * ( 1 + ($txtva / 100)), 2); $result[1] = $result[2] - $result[0]; return $result; } diff --git a/htdocs/master.inc.php b/htdocs/master.inc.php index 067c0f145c9..0ea01714d42 100644 --- a/htdocs/master.inc.php +++ b/htdocs/master.inc.php @@ -174,7 +174,27 @@ $mysoc->nom=$conf->global->MAIN_INFO_SOCIETE_NOM; $mysoc->adresse=$conf->global->MAIN_INFO_SOCIETE_ADRESSE; $mysoc->cp=$conf->global->MAIN_INFO_SOCIETE_CP; $mysoc->ville=$conf->global->MAIN_INFO_SOCIETE_VILLE; -$mysoc->pays_code=$conf->global->MAIN_INFO_SOCIETE_PAYS; +// Si dans MAIN_INFO_SOCIETE_PAYS on a un id de pays, on recupere code +if (is_numeric($conf->global->MAIN_INFO_SOCIETE_PAYS)) +{ + $mysoc->pays_id=$conf->global->MAIN_INFO_SOCIETE_PAYS; + $sql = "SELECT code from ".MAIN_DB_PREFIX."c_pays"; + $sql .= " WHERE rowid = ".$conf->global->MAIN_INFO_SOCIETE_PAYS; + $result=$db->query($sql); + if ($result) + { + $obj = $db->fetch_object(); + $mysoc->pays_code=$obj->code; + } + else { + dolibarr_print_error($db); + } +} +// Si dans MAIN_INFO_SOCIETE_PAYS on a deja un code, tout est fait +else +{ + $mysoc->pays_code=$conf->global->MAIN_INFO_SOCIETE_PAYS; +} $mysoc->tel=$conf->global->MAIN_INFO_SOCIETE_TEL; $mysoc->fax=$conf->global->MAIN_INFO_SOCIETE_FAX; $mysoc->url=$conf->global->MAIN_INFO_SOCIETE_WEB; diff --git a/htdocs/product.class.php b/htdocs/product.class.php index 12756fd2d76..6636ad9936d 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -780,6 +780,7 @@ class Product if (! $id && ! $ref) { $this->error=$langs->trans('ErrorWrongParameters'); + dolibarr_error("Product::fetch ".$this->error); return -1; } diff --git a/htdocs/propal.class.php b/htdocs/propal.class.php index 061762cced0..334370dddf4 100644 --- a/htdocs/propal.class.php +++ b/htdocs/propal.class.php @@ -1,7 +1,7 @@ * Copyright (C) 2004 Éric Seigne - * Copyright (C) 2004-2005 Laurent Destailleur + * Copyright (C) 2004-2006 Laurent Destailleur * Copyright (C) 2005 Marc Barilley / Ocebo * Copyright (C) 2005-2006 Regis Houssin * Copyright (C) 2006 Andre Cianfarani @@ -55,9 +55,6 @@ class Propal var $status; var $datep; var $fin_validite; - - var $products; - var $products_qty; var $price; var $cond_reglement_id; var $cond_reglement_code; @@ -69,9 +66,12 @@ class Propal var $note; var $note_public; - var $date_livraison; + var $date_livraison; var $adresse_livraison_id; + var $products; + var $products_qty; + var $labelstatut=array(); var $labelstatut_short=array(); @@ -125,7 +125,6 @@ class Propal * \return void * \see insert_product */ - function add_product($idproduct, $qty, $remise_percent=0) { if ($idproduct > 0) @@ -150,25 +149,31 @@ class Propal * \return int >0 si ok, <0 si ko * \see add_product */ - function insert_discount($idproduct, $qty, $remise_percent=0, $p_desc='') + function insert_discount($idproduct, $qty, $remise_percent=0, $desc='') { } /** - * \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'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 desc Descriptif optionnel + * \return int >0 si ok, <0 si ko + * \see add_product + * \remarks Les parametres sont deja censé etre juste et avec valeurs finales a l'appel + * de cette methode. Aussi, pour le taux tva, il doit deja avoir ete défini + * par l'appelant par la methode get_default_tva(societe_vendeuse,societe_acheteuse,taux_produit) + * et le desc doit deja avoir la bonne valeur (a l'appelant de gerer le multilangue) */ - function insert_product($idproduct, $qty, $remise_percent=0, $p_desc='') + function insert_product($idproduct, $qty, $remise_percent=0, $desc='') { - global $conf; - dolibarr_syslog("propal.class.php::insert_product $idproduct, $qty, $remise_percent, $p_desc"); + global $conf,$mysoc; + dolibarr_syslog("propal.class.php::insert_product $idproduct, $qty, $remise_percent, $desc"); + include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php'); + if ($this->statut == 0) { // Nettoyage parametres @@ -180,14 +185,10 @@ class Propal $prod = new Product($this->db, $idproduct); if ($prod->fetch($idproduct) > 0) { - $p_product_desc = $prod->description; - $this -> fetch_client(); - if($this->client->tva_assuj == "0") - $txtva ="0"; - else - $txtva=$prod->tva_tx; + $this->fetch_client(); + // multiprix - if($conf->global->PRODUIT_MULTIPRICES == 1) + if ($conf->global->PRODUIT_MULTIPRICES == 1) { $price = price2num($prod->multiprices[$this->client->price_level]); $subprice = price2num($prod->multiprices[$this->client->price_level]); @@ -197,28 +198,37 @@ class Propal $price = price2num($prod->price); $subprice = price2num($prod->price); } - /* + $txtva = get_default_tva($mysoc,$this->client,$prod->tva_tx); + if (! $desc) $desc = $prod->description; + if ($conf->global->PRODUIT_CHANGE_PROD_DESC) $desc=$prod->description; - */ + // Calcul du total TTC et de la TVA pour la ligne a partir de + // qty, pu, remise_percent et txtva + // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker + // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva. + $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva); + $total_ht = $tabprice[0]; + $total_tva = $tabprice[1]; + $total_ttc = $tabprice[2]; - // Calcul remise et nouveau prix + // Anciens indicateurs: $price, $subprice, $remise (a ne plus utiliser) $remise = 0; if ($remise_percent > 0) { $remise = round(($prod->price * $remise_percent / 100), 2); $price = $prod->price - $remise; } - if ($conf->global->PRODUIT_CHANGE_PROD_DESC) - { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."propaldet (fk_propal, fk_product, qty, price, tva_tx, description, remise_percent, subprice) VALUES "; - $sql .= " (".$this->id.",". $idproduct.",'". $qty."','". price2num($price)."','".$txtva."','".addslashes($p_product_desc)."','".price2num($remise_percent)."','".price2num($subprice)."')"; - } - else - { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."propaldet (fk_propal, fk_product, qty, price, tva_tx, description, remise_percent, subprice) VALUES "; - $sql .= " (".$this->id.",". $idproduct.",'". $qty."','". price2num($price) ."','".$txtva."','".addslashes($p_desc?$p_desc:$prod->label)."','".price2num($remise_percent)."','".price2num($subprice)."')"; - } - if ($this->db->query($sql) ) + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."propaldet (fk_propal, fk_product, qty, price, tva_tx, description, remise_percent, subprice,"; + $sql.= " total_ht, total_tva, total_ttc)"; + $sql.= " VALUES "; + $sql.= " (".$this->id.",". $idproduct.",'". $qty."','". price2num($price) ."','".$txtva."','".addslashes($desc?$desc:$prod->label)."','".price2num($remise_percent)."','".price2num($subprice)."',"; + $sql.= " '".price2num($total_ht) ."',"; + $sql.= " '".price2num($total_tva)."',"; + $sql.= " '".price2num($total_ttc)."'"; + $sql.= ")"; + + if ($this->db->query($sql)) { $this->update_price(); return 1; @@ -226,6 +236,7 @@ class Propal else { $this->error=$this->db->error(); + dolibarr_syslog("Error sql=$sql, error=".$this->error); return -1; } } @@ -244,39 +255,61 @@ class Propal /** - * \brief Ajout d'un produit dans la proposition, en base - * \param p_desc Descriptif optionnel - * \param p_price Prix - * \param p_qty Quantité - * \param p_tva_tx Taux tva - * \param remise_percent Remise effectuée sur le produit - * \return int >0 si ok, <0 si ko - * \see add_product + * \brief Ajout d'un produit dans la proposition, en base + * \param desc Descriptif optionnel + * \param pu Prix + * \param qty Quantité + * \param tva_tx Taux tva + * \param remise_percent Remise effectuée sur le produit + * \return int >0 si ok, <0 si ko + * \see add_product + * \remarks Les parametres sont deja censé etre juste et avec valeurs finales a l'appel + * de cette methode. Aussi, pour le taux tva, il doit deja avoir ete défini + * par l'appelant par la methode get_default_tva(societe_vendeuse,societe_acheteuse,taux_produit) + * et le desc doit deja avoir la bonne valeur (a l'appelant de gerer le multilangue) */ - function insert_product_generic($p_desc, $p_price, $p_qty, $p_tva_tx, $remise_percent=0) + function insert_product_generic($desc, $pu, $qty, $tva_tx, $remise_percent=0) { - dolibarr_syslog("propal.class.php::insert_product_generic $p_desc, $p_price, $p_qty, $p_tva_tx, $remise_percent"); + global $conf,$mysoc; + dolibarr_syslog("propal.class.php::insert_product_generic $desc, $pu, $qty, $tva_tx, $remise_percent"); + include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php'); + if ($this->statut == 0) { // Nettoyage paramètres $remise_percent=price2num($remise_percent); - $p_qty=price2num($p_qty); - if (strlen(trim($p_qty))==0) $p_qty=1; - $p_price = price2num($p_price); + $qty=price2num($qty); + if (! $qty) $qty=1; + $pu = price2num($pu); + $tva_tx = price2num($tva_tx); - $price = $p_price; - $subprice = $p_price; + // Calcul du total TTC et de la TVA pour la ligne a partir de + // qty, pu, remise_percent et txtva + // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker + // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva. + $tabprice=calcul_price_total($qty, $pu, $remise_percent, $tva_tx); + $total_ht = $tabprice[0]; + $total_tva = $tabprice[1]; + $total_ttc = $tabprice[2]; + // Anciens indicateurs: $price, $subprice, $remise (a ne plus utiliser) + $price = $pu; + $subprice = $pu; if ($remise_percent > 0) { - $remise = round(($p_price * $remise_percent / 100), 2); - $price = $p_price - $remise; + $remise = round(($pu * $remise_percent / 100), 2); + $price = $pu - $remise; } - $sql = "INSERT INTO ".MAIN_DB_PREFIX."propaldet (fk_propal, fk_product, qty, price, tva_tx, description, remise_percent, subprice) VALUES "; - $sql .= " (".$this->id.", 0,'". $p_qty."','". price2num($price)."','".$p_tva_tx."','".addslashes($p_desc)."','$remise_percent', '".price2num($subprice)."') ; "; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."propaldet (fk_propal, fk_product, qty, price, tva_tx, description, remise_percent, subprice, total_ht, total_tva, total_ttc)"; + $sql.= " VALUES "; + $sql.= " (".$this->id.", 0,'". $qty."','". price2num($price)."','".$tva_tx."','".addslashes($desc)."','$remise_percent', '".price2num($subprice)."',"; + $sql.= " '".price2num($total_ht) ."',"; + $sql.= " '".price2num($total_tva)."',"; + $sql.= " '".price2num($total_ttc)."'"; + $sql.= ")"; - if ($this->db->query($sql) ) + if ($this->db->query($sql)) { if ($this->update_price() > 0) @@ -290,6 +323,8 @@ class Propal } else { + $this->error=$this->db->error(); + dolibarr_syslog("Error sql=$sql, error=".$this->error); return -2; } } @@ -306,23 +341,39 @@ class Propal * \param desc Description * \return int 0 en cas de succès */ - - function UpdateLigne($id, $subprice, $qty, $remise_percent=0, $tva_tx, $desc='') + function UpdateLigne($id, $pu, $qty, $remise_percent=0, $tva_tx, $desc='') { + global $conf,$mysoc; + dolibarr_syslog("propal.class.php::updateligne $id, $pu, $qty, $remise_percent, $tva_tx, $desc"); + include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php'); + if ($this->statut == 0) { - // Nettoyage paramètres - $subprice=price2num($subprice); - $price = $subprice; + // Nettoyage paramètres $remise_percent=price2num($remise_percent); - $tva_tx=price2num($tva_tx); + $qty=price2num($qty); + if (! $qty) $qty=1; + $pu = price2num($pu); + $tva_tx = price2num($tva_tx); + + // Calcul du total TTC et de la TVA pour la ligne a partir de + // qty, pu, remise_percent et txtva + // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker + // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva. + $tabprice=calcul_price_total($qty, $pu, $remise_percent, $tva_tx); + $total_ht = $tabprice[0]; + $total_tva = $tabprice[1]; + $total_ttc = $tabprice[2]; + // Anciens indicateurs: $price, $subprice, $remise (a ne plus utiliser) + $price = $pu; + $subprice = $pu; if ($remise_percent > 0) { - $remise = round(($subprice * $remise_percent / 100), 2); - $price = $subprice - $remise; + $remise = round(($pu * $remise_percent / 100), 2); + $price = $pu - $remise; } - + $sql = "UPDATE ".MAIN_DB_PREFIX."propaldet "; $sql.= " SET qty='".$qty."'"; $sql.= " , price='". price2num($price)."'"; @@ -330,6 +381,9 @@ class Propal $sql.= " , subprice='".$subprice."'"; $sql.= " , tva_tx='".$tva_tx."'"; $sql.= " , description='".addslashes($desc)."'"; + $sql.= " , total_ht='".price2num($total_ht)."'"; + $sql.= " , total_tva='".price2num($total_tva)."'"; + $sql.= " , total_ttc='".price2num($total_ttc)."'"; $sql.= " WHERE rowid = '".$id."';"; if ($this->db->query($sql)) @@ -340,7 +394,7 @@ class Propal else { $this->error=$this->db->error(); - dolibarr_syslog("Propal::UpdateLigne Erreur -1"); + dolibarr_syslog("Propal::UpdateLigne Erreur sql=$sql, error=".$this->error); return -1; } } @@ -693,9 +747,12 @@ class Propal function create() { global $langs,$conf; - // Définition paramètres + + // Nettoyage/définition paramètres $this->fin_validite = $this->datep + ($this->duree_validite * 24 * 3600); + dolibarr_syslog("Propal::create ref=".$this->ref); + $this->db->begin(); // Insertion dans la base @@ -744,6 +801,7 @@ class Propal $result=$this->db->query($sql); } + // Mise a journ infos dénormalisés $resql=$this->update_price(); if ($resql) { @@ -782,36 +840,53 @@ class Propal */ function update_price() { - include_once DOL_DOCUMENT_ROOT . "/lib/price.lib.php"; + include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php'); /* * Liste des produits a ajouter */ - $sql = "SELECT price, qty, tva_tx FROM ".MAIN_DB_PREFIX."propaldet"; + $sql = "SELECT price, qty, tva_tx, total_ht, total_tva, total_ttc"; + $sql.= " FROM ".MAIN_DB_PREFIX."propaldet"; $sql.= " WHERE fk_propal = ".$this->id; - if ( $this->db->query($sql) ) + $result = $this->db->query($sql); + if ($result) { - $num = $this->db->num_rows(); + $this->total_ht = 0; + $this->total_tva = 0; + $this->total_ttc = 0; + + $num = $this->db->num_rows($result); $i = 0; - while ($i < $num) { - $obj = $this->db->fetch_object(); + $obj = $this->db->fetch_object($result); + + $this->total_ht += $obj->total_ht; + $this->total_tva += ($obj->total_ttc - $obj->total_ht); + $this->total_ttc += $obj->total_ttc; + + // 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++; } - } - $calculs = calcul_price($products, $this->remise_percent, $this->remise_absolue); + $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)."'"; @@ -976,8 +1051,9 @@ class Propal $sql.= " WHERE fk_statut = c.id"; $sql.= " AND rowid='".$rowid."';"; + dolibarr_syslog("Propal::fecth rowid=".$rowid); + $resql=$this->db->query($sql); - if ($resql) { if ($this->db->num_rows($resql)) @@ -1010,8 +1086,8 @@ class Propal $this->statut_libelle = $obj->statut_label; $this->cond_reglement_id = $obj->fk_cond_reglement; $this->mode_reglement_id = $obj->fk_mode_reglement; - $this->date_livraison = $obj->date_livraison; - $this->adresse_livraison_id = $obj->fk_adresse_livraison; + $this->date_livraison = $obj->date_livraison; + $this->adresse_livraison_id = $obj->fk_adresse_livraison; $this->user_author_id = $obj->fk_user_author; @@ -1061,7 +1137,8 @@ class Propal * Lignes propales liées à un produit ou non */ $sql = "SELECT d.description, d.price, d.tva_tx, d.qty, d.remise_percent, d.subprice, d.fk_product,"; - $sql.= " p.label, p.description as product_desc, p.ref"; + $sql.= " d.total_ht, d.total_tva, d.total_ttc,"; + $sql.= " p.ref, p.label, p.description as product_desc"; $sql.= " FROM ".MAIN_DB_PREFIX."propaldet as d"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON d.fk_product = p.rowid"; $sql.= " WHERE d.fk_propal = ".$this->id; @@ -1077,7 +1154,7 @@ class Propal { $objp = $this->db->fetch_object($result); - $ligne = new PropaleLigne(); + $ligne = new PropaleLigne($this->db); $ligne->desc = $objp->description; // Description ligne $ligne->qty = $objp->qty; @@ -1085,6 +1162,11 @@ class Propal $ligne->subprice = $objp->subprice; $ligne->remise_percent = $objp->remise_percent; $ligne->price = $objp->price; + + $ligne->total_ht = $objp->total_ht; + $ligne->total_tva = $objp->total_tva; + $ligne->total_ttc = $objp->total_ttc; + $ligne->product_id = $objp->fk_product; $ligne->coef = $objp->coef; @@ -1101,7 +1183,7 @@ class Propal } else { - dolibarr_syslog("Propal::Fetch Erreur lecture des produits"); + dolibarr_syslog("Propal::Fetch Erreur lecture des produits sql=$sql"); return -1; } @@ -2282,13 +2364,13 @@ class PropaleLigne var $subprice; var $remise_percent; var $price; - var $product_id; var $desc; // Description ligne + var $product_id; // Id produit prédéfini // From llx_product var $libelle; // Label produit var $product_desc; // Description produit - var $ref; + var $ref; // Reference produit function PropaleLigne() { diff --git a/mysql/migration/2.0.0-2.1.0.sql b/mysql/migration/2.0.0-2.1.0.sql index 129c4da09b3..02b1889038c 100644 --- a/mysql/migration/2.0.0-2.1.0.sql +++ b/mysql/migration/2.0.0-2.1.0.sql @@ -115,7 +115,11 @@ ALTER TABLE llx_facturedet ADD COLUMN total_tva real AFTER total_ht; ALTER TABLE llx_facturedet ADD COLUMN total_ttc real AFTER total_tva; ALTER TABLE llx_facturedet ADD COLUMN info_bits integer DEFAULT 0 AFTER date_end; - +ALTER TABLE llx_propaldet ADD COLUMN total_ht real AFTER price; +ALTER TABLE llx_propaldet ADD COLUMN total_tva real AFTER total_ht; +ALTER TABLE llx_propaldet ADD COLUMN total_ttc real AFTER total_tva; +ALTER TABLE llx_propaldet ADD COLUMN info_bits integer DEFAULT 0 AFTER total_ttc; + ALTER TABLE llx_commande ADD INDEX idx_commande_fk_soc (fk_soc); ALTER TABLE llx_commande ADD CONSTRAINT fk_commande_societe FOREIGN KEY (fk_soc) REFERENCES llx_societe (idp); diff --git a/mysql/tables/llx_propaldet.sql b/mysql/tables/llx_propaldet.sql index 1f23be7931f..b43d9fde123 100644 --- a/mysql/tables/llx_propaldet.sql +++ b/mysql/tables/llx_propaldet.sql @@ -32,6 +32,10 @@ create table llx_propaldet fk_remise_except integer NULL, -- Lien vers table des remises fixes subprice real, -- prix avant remise price real, -- prix final + total_ht real, -- Total HT de la ligne toute quantité et incluant remise ligne et globale + total_tva real, -- Total TVA de la ligne toute quantité et incluant remise ligne et globale + total_ttc real, -- Total TTC de la ligne toute quantité et incluant remise ligne et globale + info_bits integer DEFAULT 0, -- TVA NPR ou non coef real, -- coefficient de marge rang integer DEFAULT 0 )type=innodb;