diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index 1b5cc0b3737..05c8d2b41b7 100644 --- a/htdocs/facture.class.php +++ b/htdocs/facture.class.php @@ -438,7 +438,7 @@ class Facture extends CommonObject $this->paye = $obj->paye; $this->close_code = $obj->close_code; $this->close_note = $obj->close_note; - $this->socid = $obj->fk_soc; + $this->socid = $obj->fk_soc; $this->statut = $obj->fk_statut; $this->date_lim_reglement = $obj->dlr; $this->mode_reglement_id = $obj->fk_mode_reglement; @@ -505,7 +505,7 @@ class Facture extends CommonObject /** - \brief Recupére les lignes de factures + \brief Recupére les lignes de factures dans this->lignes \return int 1 si ok, < 0 si erreur */ function fetch_lines() @@ -530,7 +530,7 @@ class Facture extends CommonObject { $objp = $this->db->fetch_object($result); $faclig = new FactureLigne($this->db); - $faclig->rowid = $objp->rowid; + $faclig->rowid = $objp->rowid; $faclig->desc = $objp->description; // Description ligne $faclig->libelle = $objp->label; // Label produit $faclig->product_desc = $objp->product_desc; // Description produit @@ -1339,93 +1339,92 @@ class Facture extends CommonObject * 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, $date_start='', $date_end='', $ventil=0, $info_bits='', $fk_remise_except='', $price_base_type='HT', $pu_ttc=0) - { - global $conf; - dolibarr_syslog("Facture::Addline $facid,$desc,$pu,$qty,$txtva,$fk_product,$remise_percent,$date_start,$date_end,$ventil,$info_bits", LOG_DEBUG); - include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php'); + function addline($facid, $desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $fk_remise_except='', $price_base_type='HT', $pu_ttc=0) + { + dolibarr_syslog("Facture::Addline $facid,$desc,$pu,$qty,$txtva,$fk_product,$remise_percent,$date_start,$date_end,$ventil,$info_bits", LOG_DEBUG); + include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php'); - if ($this->brouillon) - { - $this->db->begin(); + if ($this->brouillon) + { + $this->db->begin(); - // Nettoyage paramètres - $remise_percent=price2num($remise_percent); - $qty=price2num($qty); - if (! $qty) $qty=1; - if (! $ventil) $ventil=0; - if (! $info_bits) $info_bits=0; - $pu = price2num($pu); - $txtva=price2num($txtva); + // Nettoyage paramètres + $remise_percent=price2num($remise_percent); + $qty=price2num($qty); + if (! $qty) $qty=1; + if (! $ventil) $ventil=0; + if (! $info_bits) $info_bits=0; + $pu = price2num($pu); + $txtva=price2num($txtva); - // 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, 0, $price_base_type, $pu_ttc); - $total_ht = $tabprice[0]; - $total_tva = $tabprice[1]; - $total_ttc = $tabprice[2]; + // 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, 0, $price_base_type, $pu_ttc); + $total_ht = $tabprice[0]; + $total_tva = $tabprice[1]; + $total_ttc = $tabprice[2]; - // Anciens indicateurs: $price, $remise (a ne plus utiliser) - $price = $pu; - $remise = 0; - if ($remise_percent > 0) - { - $remise = round(($pu * $remise_percent / 100),2); - $price = ($pu - $remise); - } + // Anciens indicateurs: $price, $remise (a ne plus utiliser) + $price = $pu; + $remise = 0; + if ($remise_percent > 0) + { + $remise = round(($pu * $remise_percent / 100),2); + $price = ($pu - $remise); + } - // Insertion ligne - $ligne=new FactureLigne($this->db); + // Insertion ligne + $ligne=new FactureLigne($this->db); - $ligne->fk_facture=$facid; - $ligne->desc=$desc; - $ligne->qty=$qty; - $ligne->txtva=$txtva; - $ligne->fk_product=$fk_product; - $ligne->remise_percent=$remise_percent; - $ligne->subprice=$pu; - $ligne->date_start=$date_start; - $ligne->date_end=$date_end; - $ligne->ventil=$ventil; - $ligne->rang=-1; - $ligne->info_bits=$info_bits; - $ligne->fk_remise_except=$fk_remise_except; - $ligne->total_ht=$total_ht; - $ligne->total_tva=$total_tva; - $ligne->total_ttc=$total_ttc; + $ligne->fk_facture=$facid; + $ligne->desc=$desc; + $ligne->qty=$qty; + $ligne->txtva=$txtva; + $ligne->fk_product=$fk_product; + $ligne->remise_percent=$remise_percent; + $ligne->subprice=$pu; + $ligne->date_start=$date_start; + $ligne->date_end=$date_end; + $ligne->ventil=$ventil; + $ligne->rang=-1; + $ligne->info_bits=$info_bits; + $ligne->fk_remise_except=$fk_remise_except; + $ligne->total_ht=$total_ht; + $ligne->total_tva=$total_tva; + $ligne->total_ttc=$total_ttc; - // A ne plus utiliser - $ligne->price=$price; - $ligne->remise=$remise; + // A ne plus utiliser + $ligne->price=$price; + $ligne->remise=$remise; - $result=$ligne->insert(); - if ($result > 0) - { - // Mise a jour informations denormalisees au niveau de la facture meme - $result=$this->update_price($facid); - if ($result > 0) - { - $this->db->commit(); - return 1; - } - else - { - $this->error=$this->db->error(); - dolibarr_syslog("Error sql=$sql, error=".$this->error); - $this->db->rollback(); - return -1; - } - } - else - { - $this->error=$ligne->error; - $this->db->rollback(); - return -2; - } - } - } + $result=$ligne->insert(); + if ($result > 0) + { + // Mise a jour informations denormalisees au niveau de la facture meme + $result=$this->update_price($facid); + if ($result > 0) + { + $this->db->commit(); + return 1; + } + else + { + $this->error=$this->db->error(); + dolibarr_syslog("Error sql=$sql, error=".$this->error); + $this->db->rollback(); + return -1; + } + } + else + { + $this->error=$ligne->error; + $this->db->rollback(); + return -2; + } + } + } /** * \brief Mets à jour une ligne de facture @@ -2073,47 +2072,47 @@ class Facture extends CommonObject } } - /** - * \brief Charge les informations de l'onglet info dans l'objet facture - * \param id Id de la facture a charger - */ - function info($id) - { - $sql = 'SELECT c.rowid, '.$this->db->pdate('datec').' as datec,'; - $sql.= ' '.$this->db->pdate('date_valid').' as datev,'; - $sql.= ' fk_user_author, fk_user_valid'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'facture as c'; - $sql.= ' WHERE c.rowid = '.$id; + /** + * \brief Charge les informations de l'onglet info dans l'objet facture + * \param id Id de la facture a charger + */ + function info($id) + { + $sql = 'SELECT c.rowid, '.$this->db->pdate('datec').' as datec,'; + $sql.= ' '.$this->db->pdate('date_valid').' as datev,'; + $sql.= ' fk_user_author, fk_user_valid'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'facture as c'; + $sql.= ' WHERE c.rowid = '.$id; - $result=$this->db->query($sql); - if ($result) - { - if ($this->db->num_rows($result)) - { - $obj = $this->db->fetch_object($result); - $this->id = $obj->rowid; - if ($obj->fk_user_author) - { - $cuser = new User($this->db, $obj->fk_user_author); - $cuser->fetch(); - $this->user_creation = $cuser; - } - if ($obj->fk_user_valid) - { - $vuser = new User($this->db, $obj->fk_user_valid); - $vuser->fetch(); - $this->user_validation = $vuser; - } - $this->date_creation = $obj->datec; - $this->date_validation = $obj->datev; - } - $this->db->free($result); - } - else - { - dolibarr_print_error($this->db); - } - } + $result=$this->db->query($sql); + if ($result) + { + if ($this->db->num_rows($result)) + { + $obj = $this->db->fetch_object($result); + $this->id = $obj->rowid; + if ($obj->fk_user_author) + { + $cuser = new User($this->db, $obj->fk_user_author); + $cuser->fetch(); + $this->user_creation = $cuser; + } + if ($obj->fk_user_valid) + { + $vuser = new User($this->db, $obj->fk_user_valid); + $vuser->fetch(); + $this->user_validation = $vuser; + } + $this->date_creation = $obj->datec; + $this->date_validation = $obj->datev; + } + $this->db->free($result); + } + else + { + dolibarr_print_error($this->db); + } + } /** * \brief Change les conditions de réglement de la facture diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php index c42c2f15d4c..fd924b5120b 100644 --- a/htdocs/fourn/facture/fiche.php +++ b/htdocs/fourn/facture/fiche.php @@ -30,8 +30,9 @@ */ require_once('./pre.inc.php'); -require_once('./paiementfourn.class.php'); +require_once(DOL_DOCUMENT_ROOT.'/fourn/facture/paiementfourn.class.php'); require_once(DOL_DOCUMENT_ROOT.'/lib/fourn.lib.php'); +require_once(DOL_DOCUMENT_ROOT.'/product.class.php'); if (!$user->rights->fournisseur->facture->lire) @@ -74,14 +75,14 @@ if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes') } } -if ($_POST['action'] == 'confirm_deleteproductline' && $_POST['confirm'] == 'yes' && $conf->global->PRODUIT_CONFIRM_DELETE_LINE) +if ($_POST['action'] == 'confirm_deleteproductline' && $_POST['confirm'] == 'yes') { if ($user->rights->fournisseur->facture->creer) { $facturefourn = new FactureFournisseur($db); $facturefourn->fetch($_GET['facid']); $facturefourn->deleteline($_GET['ligne_id']); - $_GET['action'] = 'edit'; + $_GET['action'] = ''; } } @@ -111,7 +112,7 @@ if ($_POST['action'] == 'modif_libelle') } -if ($_POST['action'] == 'update') +if ($_POST['action'] == 'update' && ! $_POST['cancel']) { $datefacture = $db->idate(mktime(12, 0 , 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear'])); $date_echeance = $db->idate(mktime(12,0,0,$_POST['echmonth'],$_POST['echday'],$_POST['echyear'])); @@ -204,12 +205,12 @@ if ($_POST['action'] == 'add' && $user->rights->fournisseur->facture->creer) } else { - $mesg='
'.$langs->trans('ErrorFieldRequired',$langs->trans('Ref')).'
'; + $mesg='
'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('Ref')).'
'; $_GET['action']='create'; } } -if ($_GET['action'] == 'del_ligne' && !$conf->global->PRODUIT_CONFIRM_DELETE_LINE) +if ($_GET['action'] == 'del_ligne') { $facfou = new FactureFournisseur($db,'',$_GET['facid']); $facfou->deleteline($_GET['ligne_id']); @@ -217,15 +218,14 @@ if ($_GET['action'] == 'del_ligne' && !$conf->global->PRODUIT_CONFIRM_DELETE_LIN } // Modification d'une ligne -if ($_GET['action'] == 'mod_ligne') +if ($_REQUEST['action'] == 'mod_ligne') { - if ($_GET['etat'] == '1' && !$_GET['cancel']) // si on valide la modification + if ($_REQUEST['etat'] == '1' && ! $_REQUEST['cancel']) // si on valide la modification { $facfou = new FactureFournisseur($db,'',$_GET['facid']); $facfou->updateline($_GET['ligne_id'], $_POST['label'], $_POST['puht'], $_POST['tauxtva'], $_POST['qty']); } - $_GET['action'] = 'edit'; } if ($_GET['action'] == 'add_ligne') @@ -241,10 +241,18 @@ if ($_GET['action'] == 'add_ligne') // $label = '['.$nv_prod->ref.'] - '. $nv_prod->libelle; $label = $nv_prod->libelle; - $result=$nv_prod->get_buyprice($_POST['fourn_id'], $_POST['qty']); + $result=$nv_prod->get_buyprice($_POST['socid'], $_POST['qty']); if ($result > 0) { - $facfou->addline($label, $nv_prod->fourn_pu, $nv_prod->tva_tx, $_POST['qty'], $_POST['idprod']); + $societe=''; + if ($_POST['socid']) + { + $societe=new Societe($db); + $societe->fetch($_POST['socid']); + } + + $tvatx=get_default_tva($societe,$mysoc,$nv_prod->tva_tx); + $facfou->addline($label, $nv_prod->fourn_pu, $tvatx, $_POST['qty'], $_POST['idprod']); } if ($result == -1) { @@ -257,7 +265,7 @@ if ($_GET['action'] == 'add_ligne') $tauxtva = price2num($_POST['tauxtva']); if (! $_POST['label']) { - $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->trans("Label")).'
'; + $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")).'
'; } else { @@ -274,21 +282,21 @@ if ($_GET['action'] == 'add_ligne') } } } - $_GET['action'] = 'edit'; + $_GET['action'] = ''; } -/********************************************************************* -* -* Mode creation -* -**********************************************************************/ +/* +* Affichage page +*/ +$addons=''; +llxHeader('','', $addons); + +// Mode creation if ($_GET['action'] == 'create' or $_GET['action'] == 'copy') { - llxHeader(); - print_titre($langs->trans('NewBill')); if ($mesg) { print $mesg.'
'; } @@ -402,34 +410,18 @@ else /* */ /* *************************************************************************** */ + $productstatic = new Product($db); + $fac = new FactureFournisseur($db); $fac->fetch($_GET['facid']); $societe = new Fournisseur($db); - if ($societe->fetch($fac->socid)) - { - $addons[0][0] = DOL_URL_ROOT.'/fourn/fiche.php?socid='.$fac->socid; - $addons[0][1] = $societe->nom; - } + $societe->fetch($fac->socid); - llxHeader('','', $addons); - - if ($mesg) { print $mesg.'
'; } - - - if ($_GET['action'] == 'edit' || $_GET['action'] == 'delete_product_line') + if ($_GET['action'] == 'edit') { print_titre($langs->trans('SupplierInvoice')); - /* - * Confirmation de la suppression d'une ligne produit - */ - if ($_GET['action'] == 'delete_product_line' && $conf->global->PRODUIT_CONFIRM_DELETE_LINE) - { - $html->form_confirm($_SERVER["PHP_SELF"].'?facid='.$fac->id.'&action=edit&ligne_id='.$_GET["ligne_id"], $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteproductline'); - print '
'; - } - print '
'; print ''; @@ -437,14 +429,15 @@ else print ''.$langs->trans('Company').''; print ''.$societe->getNomUrl(1).''; - print ''.$langs->trans('NotePublic').''; + print ''.$langs->trans('NotePublic').''; + print ''; print ''.$langs->trans('Ref').''; print ''; - $rownb=9; + $rownb=8; print ''; - print ''; @@ -467,7 +460,12 @@ else print ''.price($fac->total_ttc).''; print ''.$langs->trans('Status').''.$fac->getLibStatut(4).''; - print ''; + print ''; + print ''; + print '     '; + print ''; + + print ''; print ''; print '
'; @@ -486,97 +484,25 @@ else print ''.$langs->trans('TotalHT').''; print ''.$langs->trans('VATRate').''; print ''.$langs->trans('VAT').''; - print ''.$langs->trans('TotalTTC').' '; + print ''.$langs->trans('TotalTTC').''; + print ' '; for ($i = 0 ; $i < sizeof($fac->lignes) ; $i++) { $var=!$var; - // Ligne en modification - if ($_GET['etat'] == '0' && $_GET['ligne_id'] == $fac->lignes[$i]->rowid) - { - print '
'; - print ''; - print ''; - print ''; - print ' '; - print ''; - print ''; - print ''; - $html->select_tva('tauxtva',$fac->lignes[$i]->tva_taux,$societe,$mysoc); - print ''; - print ''; - print ''; - print ''; - print '
'; - print ''; - print '
'; - } - else // Affichage simple de la ligne - { - print ''.$fac->lignes[$i]->description.''; - print ''.price($fac->lignes[$i]->pu_ht).''; - print ''.price($fac->lignes[$i]->pu_ht * (1+($fac->lignes[$i]->tva_taux/100))).''; - print ''.$fac->lignes[$i]->qty.''; - print ''.price($fac->lignes[$i]->total_ht).''; - print ''.$fac->lignes[$i]->tva_taux.''; - print ''.price($fac->lignes[$i]->tva).''; - print ''.price($fac->lignes[$i]->total_ttc).''; - print ''.img_edit().''; - if ($conf->global->PRODUIT_CONFIRM_DELETE_LINE) - { - print ''.img_delete().''; - } - else - { - print ''.img_delete().''; - } - print ''; - } + // Affichage simple de la ligne + print ''.$fac->lignes[$i]->description.''; + print ''.price($fac->lignes[$i]->pu_ht).''; + print ''.price($fac->lignes[$i]->pu_ht * (1+($fac->lignes[$i]->tva_taux/100))).''; + print ''.$fac->lignes[$i]->qty.''; + print ''.price($fac->lignes[$i]->total_ht).''; + print ''.$fac->lignes[$i]->tva_taux.''; + print ''.price($fac->lignes[$i]->tva).''; + print ''.price($fac->lignes[$i]->total_ttc).''; + print ''.img_edit().''; + print ''.img_delete().''; + print ''; } - /* Nouvelle ligne */ - $var=!$var; - print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print '-'; - print ''; - $html->select_tva('tauxtva','',$societe,$mysoc); - print ''; - print ' '; - print ''; - print '
'; - - // Ajout de produits/services prédéfinis - if ($conf->produit->enabled) - { - print '
'; - print ''; - $var=! $var; - print ''; - print ''; - $html->select_produits_fournisseurs($fac->socid,'','idprod',$filtre); - print ''; - print ''; - print ' '; - print ' '; - print ' '; - print ' '; - print ''; - print ''; - print '
'; - } - print ''; } else @@ -588,7 +514,16 @@ else $titre=$langs->trans('SupplierInvoice'); dolibarr_fiche_head($head, 'card', $titre); + if ($mesg) { print $mesg.'
'; } + /* + * Confirmation de la suppression d'une ligne produit + */ + if ($_GET['action'] == 'confirm_delete_line') + { + $html->form_confirm($_SERVER["PHP_SELF"].'?facid='.$fac->id.'&ligne_id='.$_GET["ligne_id"], $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteproductline'); + print '
'; + } /* * Confirmation de la validation * @@ -737,32 +672,124 @@ else print ''; print ''; print ''; + print ''; print ''; print ''; print ''; print ''; - print ''; + print ''; + print ''; + print ''; + print ''; $var=1; for ($i = 0 ; $i < sizeof($fac->lignes) ; $i++) { $var=!$var; - print ''; - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; + // Ligne en modification + if ($_GET['action'] == 'mod_ligne' && $_GET['etat'] == '0' && $_GET['ligne_id'] == $fac->lignes[$i]->rowid) + { + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + } + else // Affichage simple de la ligne + { + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + } + } + + if ($_GET['action'] != 'mod_ligne') + { + /* Nouvelle ligne */ + $var=!$var; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + // Ajout de produits/services prédéfinis + if ($conf->produit->enabled) + { + print ''; + print ''; + print ''; + print ''; + $var=! $var; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + } + } + print '
'.$langs->trans('Label').''.$langs->trans('PriceUHT').''.$langs->trans('PriceUTTC').''.$langs->trans('Qty').''.$langs->trans('TotalHT').''.$langs->trans('VATRate').''.$langs->trans('VAT').''.$langs->trans('TotalTTC').'
'.$langs->trans('TotalTTC').'  
'; - print ''.img_object($langs->trans("ShowProduct"),'product').' '; - print $fac->lignes[$i]->description; - print ''; - print ''.price($fac->lignes[$i]->pu_ht).''.$fac->lignes[$i]->qty.''.price($fac->lignes[$i]->total_ht).''.$fac->lignes[$i]->tva_taux.' %'.price($fac->lignes[$i]->tva).''.price($fac->lignes[$i]->total_ttc).'
 '; + $html->select_tva('tauxtva',$fac->lignes[$i]->tva_taux,$societe,$mysoc); + print ''; + print '
'; + if ($fac->lignes[$i]->fk_product) + { + $productstatic->id=$fac->lignes[$i]->fk_product; + $productstatic->type=1; + $productstatic->ref=$fac->lignes[$i]->libelle; + print $productstatic->getNomUrl(1); + } + else + { + print $fac->lignes[$i]->description; + } + print ''.price($fac->lignes[$i]->pu_ht).''.price($fac->lignes[$i]->pu_ht * (1+($fac->lignes[$i]->tva_taux/100))).''.$fac->lignes[$i]->qty.''.price($fac->lignes[$i]->total_ht).''.$fac->lignes[$i]->tva_taux.''.price($fac->lignes[$i]->tva).''.price($fac->lignes[$i]->total_ttc).''.img_edit().''.img_delete().'
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print '-'; + $html->select_tva('tauxtva','',$societe,$mysoc); + print ''; + print ' '; + print '
'; + $html->select_produits_fournisseurs($fac->socid,'','idprod',$filtre); + print '    
'; + print ''; } @@ -775,11 +802,7 @@ else if ($fac->statut == 0 && $user->societe_id == 0) { - if ($_GET['action'] == 'edit') - { - print ''.$langs->trans('Cancel').''; - } - else + if ($_GET['action'] != 'edit') { print ''.$langs->trans('Edit').''; } diff --git a/htdocs/fourn/fournisseur.facture.class.php b/htdocs/fourn/fournisseur.facture.class.php index 40af8a8446b..66b0d4bb881 100644 --- a/htdocs/fourn/fournisseur.facture.class.php +++ b/htdocs/fourn/fournisseur.facture.class.php @@ -171,13 +171,15 @@ class FactureFournisseur extends Facture $sql.= ' s.nom as socnom, s.idp as socid'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as f,'.MAIN_DB_PREFIX.'societe as s'; $sql.= ' WHERE f.rowid='.$rowid.' AND f.fk_soc = s.idp'; + + dolibarr_syslog("FactureFourn::Fetch sql=".$sql, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $num=$this->db->num_rows($resql); if ($num) { - $obj = $this->db->fetch_object(); + $obj = $this->db->fetch_object($resql); $this->id = $rowid; $this->datep = $obj->df; @@ -206,28 +208,36 @@ class FactureFournisseur extends Facture /* * Lignes */ - $sql = 'SELECT rowid, description, pu_ht, qty, tva_taux, tva, total_ht, total_ttc, fk_product'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'facture_fourn_det'; - $sql .= ' WHERE fk_facture_fourn='.$this->id; + $sql = 'SELECT f.rowid, f.description, f.pu_ht, f.qty, f.tva_taux, f.tva,'; + $sql.= ' f.total_ht, f.tva as total_tva, f.total_ttc, f.fk_product,'; + $sql.= ' p.label as label, p.description as product_desc'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn_det as f'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON f.fk_product = p.rowid'; + $sql.= ' WHERE fk_facture_fourn='.$this->id; + + dolibarr_syslog("FactureFourn::Fetch search lines sql=".$sql, LOG_DEBUG); $resql_rows = $this->db->query($sql); if ($resql_rows) { $num_rows = $this->db->num_rows($resql_rows); - $i = 0; if ($num_rows) { + $i = 0; while ($i < $num_rows) { $obj = $this->db->fetch_object($resql_rows); + $this->lignes[$i]->rowid = $obj->rowid; $this->lignes[$i]->description = $obj->description; + $this->lignes[$i]->libelle = $obj->label; // Label produit + $this->lignes[$i]->product_desc = $obj->product_desc; // Description produit $this->lignes[$i]->pu_ht = $obj->pu_ht; $this->lignes[$i]->tva_taux = $obj->tva_taux; $this->lignes[$i]->qty = $obj->qty; - $this->lignes[$i]->total_ht = $obj->total_ht; $this->lignes[$i]->tva = $obj->tva; - $this->lignes[$i]->total_ttc = $obj->total_ttc; - $this->lignes[$i]->rowid = $obj->rowid; + $this->lignes[$i]->total_ht = $obj->total_ht; $this->lignes[$i]->total_tva = $obj->total_tva; + $this->lignes[$i]->total_ttc = $obj->total_ttc; + $this->lignes[$i]->fk_product = $obj->fk_product; $i++; } } @@ -235,7 +245,7 @@ class FactureFournisseur extends Facture } else { - dolibarr_syslog('Erreur FactureFournisseur::Fetch rowid='.$rowid.', Erreur dans fetch des lignes'); + dolibarr_syslog('FactureFournisseur::Fetch rowid='.$rowid.', Erreur dans fetch des lignes'); $this->error=$this->db->error(); dolibarr_print_error($this->db); return -3; @@ -243,7 +253,7 @@ class FactureFournisseur extends Facture } else { - dolibarr_syslog('Erreur FactureFournisseur::Fetch rowid='.$rowid.' numrows=0 sql='.$sql); + dolibarr_syslog('FactureFournisseur::Fetch rowid='.$rowid.' numrows=0 sql='.$sql); $this->error='Bill with id '.$rowid.' not found sql='.$sql; dolibarr_print_error($this->db); return -2; @@ -252,7 +262,7 @@ class FactureFournisseur extends Facture } else { - dolibarr_syslog('Erreur FactureFournisseur::Fetch rowid='.$rowid.' Erreur dans fetch de la facture fournisseur'); + dolibarr_syslog('FactureFournisseur::Fetch rowid='.$rowid.' Erreur dans fetch de la facture fournisseur'); $this->error=$this->db->error(); dolibarr_print_error($this->db); return -1; @@ -342,32 +352,69 @@ class FactureFournisseur extends Facture /** - * \brief Ajoute une ligne de facture (associé à aucun produit/service prédéfini) - * \param desc description de la ligne - * \param pu prix unitaire - * \param tauxtva taux de tva - * \param qty quantité - * \param idproduct id produit - */ - function addline($desc, $pu, $tauxtva, $qty, $idproduct=0) + * \brief Ajoute une ligne de facture (associé à aucun produit/service prédéfini) + * \param desc Description de la ligne + * \param pu Prix unitaire + * \param txtva Taux de tva forcé, sinon -1 + * \param qty Quantité + * \param fk_product Id du produit/service predéfini + * \param remise_percent Pourcentage de remise de la ligne + * \param date_start Date de debut de validité du service + * \param date_end Date de fin de validité du service + * \param ventil Code de ventilation comptable + * \param info_bits Bits de type de lignes + * \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($desc, $pu, $txtva, $qty, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $fk_remise_except='', $price_base_type='HT', $pu_ttc=0) { + dolibarr_syslog("FactureFourn::Addline $desc,$pu,$qty,$txtva,$fk_product,$remise_percent,$date_start,$date_end,$ventil,$info_bits", LOG_DEBUG); + include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php'); + + $this->db->begin(); + + // Nettoyage paramètres + $txtva=price2num($txtva); + + // 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, 0, $txtva, 0, 'HT', 0); + $total_ht = $tabprice[0]; + $total_tva = $tabprice[1]; + $total_ttc = $tabprice[2]; + $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facture_fourn_det (fk_facture_fourn)'; $sql .= ' VALUES ('.$this->id.');'; $resql = $this->db->query($sql); if ($resql) { $idligne = $this->db->last_insert_id(MAIN_DB_PREFIX.'facture_fourn_det'); - $this->updateline($idligne, $desc, $pu, $tauxtva, $qty, $idproduct); + $this->updateline($idligne, $desc, $pu, $txtva, $qty, $fk_product); // Mise a jour prix facture - $this->update_price($this->id); - - return 1; + $result=$this->update_price($this->id); + if ($result > 0) + { + $this->db->commit(); + return 1; + } + else + { + $this->error=$this->db->error(); + dolibarr_syslog("Error sql=$sql, error=".$this->error); + $this->db->rollback(); + return -1; + } } else { - dolibarr_print_error($this->db); - return -1; + $this->error=$ligne->error; + $this->db->rollback(); + return -2; } } diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php index 37cffbc5b7d..43b240a4cbe 100644 --- a/htdocs/product/fiche.php +++ b/htdocs/product/fiche.php @@ -979,17 +979,17 @@ if ($_GET["id"] && $_GET["action"] == '' && $product->status) { $langs->load("propal"); - print ''; - print_titre($langs->trans("AddToMyProposals")) . ''; + print ''; + print $langs->trans("AddToMyProposals") . ''; if ($user->rights->commercial->client->voir) { - print ''; - print_titre($langs->trans("AddToOtherProposals")) . ''; + print ''; + print $langs->trans("AddToOtherProposals").''; } else { - print ' '; + print ' '; } print ''; @@ -1093,17 +1093,17 @@ if ($_GET["id"] && $_GET["action"] == '' && $product->status) { $langs->load("orders"); - print ''; - print_titre($langs->trans("AddToMyOrders")) . ''; + print ''; + print $langs->trans("AddToMyOrders").''; if ($user->rights->commercial->client->voir) { - print ''; - print_titre($langs->trans("AddToOtherOrders")) . ''; + print ''; + print $langs->trans("AddToOtherOrders").''; } else { - print ''; + print ' '; } print ''; @@ -1203,19 +1203,19 @@ if ($_GET["id"] && $_GET["action"] == '' && $product->status) print ''; - print_titre($langs->trans("AddToMyBills")); + print $langs->trans("AddToMyBills").''; if ($user->rights->commercial->client->voir) { - print ''; - print_titre($langs->trans("AddToOtherBills")); + print ''; + print $langs->trans("AddToOtherBills").''; } else { - print ''; + print ' '; } - print ''; + print ''; // Liste de Mes factures print ''; @@ -1298,7 +1298,7 @@ if ($_GET["id"] && $_GET["action"] == '' && $product->status) print '
'; print ""; print "factureid\">$objp->facnumber\n"; - print "idp\">$objp->nom\n"; + print "idp\">".dolibarr_trunc($objp->nom,24)."\n"; print "".$langs->trans("Qty"); print ''; print ""; diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php index 91e54a8c214..490632c1c86 100644 --- a/htdocs/product/fournisseurs.php +++ b/htdocs/product/fournisseurs.php @@ -102,7 +102,7 @@ if ($_POST["action"] == 'updateprice' && $_POST["cancel"] <> $langs->trans("Canc else { $error++; - $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->trans("Ref")).'
'; + $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref")).'
'; } if ($_POST["qty"]) @@ -123,13 +123,13 @@ if ($_POST["action"] == 'updateprice' && $_POST["cancel"] <> $langs->trans("Canc else { $error++; - $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->trans("Price")).'
'; + $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Price")).'
'; } } else { $error++; - $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->trans("Qty")).'
'; + $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Qty")).'
'; } if (! $error) @@ -152,211 +152,212 @@ if ($_POST["cancel"] == $langs->trans("Cancel")) /* - * Fiche produit + * Affichage fiche */ + if ($_GET["id"] || $_GET["ref"]) { - if ($_GET["action"] <> 're-edit') - { - $product = new Product($db); - if ($_GET["ref"]) $result = $product->fetch('',$_GET["ref"]); - if ($_GET["id"]) $result = $product->fetch($_GET["id"]); - llxHeader("","",$langs->trans("CardProduct".$product->type)); - } - - if ( $result ) - { - - if ($_GET["action"] <> 'edit' && $_GET["action"] <> 're-edit') + if ($_GET["action"] <> 're-edit') { - /* - * En mode visu - */ - - $head=product_prepare_head($product, $user); - $titre=$langs->trans("CardProduct".$product->type); - dolibarr_fiche_head($head, 'suppliers', $titre); - - - print ''; - - // Reference - print ''; - print ''; - print ''; - - // Libelle - print ''; - - // Prix - print ''; - - // Statut - print ''; - - print '
'.$langs->trans("Ref").''; - $product->load_previous_next_ref(); - $previous_ref = $product->ref_previous?''.img_previous().'':''; - $next_ref = $product->ref_next?''.img_next().'':''; - if ($previous_ref || $next_ref) print '
'; - print ''.$product->ref.''; - if ($previous_ref || $next_ref) print ''.$previous_ref.''.$next_ref.'
'; - print '
'.$langs->trans("Label").''.$product->libelle.'
'.$langs->trans("SellingPrice").''.price($product->price).'
'.$langs->trans("Status").''; - print $product->getLibStatut(2); - print '
'; - - print "\n"; - - if ($mesg) print($mesg); - - - // Formulaire ajout prix - if ($_GET["action"] == 'add_price' && $user->rights->produit->creer) - { - $langs->load("suppliers"); - - if ($_GET["id_fourn"]) { - print_fiche_titre($langs->trans("ChangeSupplierPrice")); - } else { - print_fiche_titre($langs->trans("AddSupplierPrice")); - } - print ''; - print ''; - print ''; - - if ($_GET["id_fourn"]) { - print ''; - $product->fetch_fourn_data($_GET["id_fourn"]); - print ''; - } else { - print ''; - print ''; - } - - print ''; - $quantity = $_GET["qty"] ? $_GET["qty"] : "1"; - print ''; - print ''; - print ''; - - print ''; - print ''; - print '
'.$langs->trans("Supplier").''; - $html=new Form($db); - $html->select_societes('','id_fourn','fournisseur=1'); - print '
'.$langs->trans("Ref").''; - print ''; - print '
'.$langs->trans("Qty").''.$langs->trans("Price").'
 '; - print '
'; - } - - /* ************************************************************************** */ - /* */ - /* Barre d'action */ - /* */ - /* ************************************************************************** */ - - print "\n
\n"; - - if ($_GET["action"] != 'add_price') { - - if ($user->rights->produit->creer) - { - print ''; - print $langs->trans("AddSupplier").''; - } - - } - - print "\n
\n"; - print '
'; - - - if ($user->rights->fournisseur->lire) { - // Titre liste des fournisseurs - print ''; - if ($product->isproduct()) $nblignefour=4; - else $nblignefour=4; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - // Liste des fournisseurs - $sql = "SELECT s.nom, s.idp, pf.ref_fourn, pfp.price, pfp.quantity"; - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."product_fournisseur as pf"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp"; - $sql.= " ON pf.fk_soc = pfp.fk_soc AND pf.fk_product = pfp.fk_product"; - $sql.= " WHERE pf.fk_soc = s.idp AND pf.fk_product = ".$product->id; - $sql.= " ORDER BY lower(s.nom), pfp.quantity"; - - $resql=""; - $resql=$db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - $i = 0; - - $var=True; - while ($i < $num) - { - $objp = $db->fetch_object($resql); - $var=!$var; - - print ""; - print ''; - - // Fournisseur - print ''; - - // Quantité - print ''; - - // Prix quantité - print ''; - - // Prix unitaire - print ''; - - // Modifier-Supprimer - print ''; - - print ''; - - $i++; - } - - $db->free($resql); - } - else { - dolibarr_print_error($db); - } - - print '
'; - print $langs->trans("Suppliers").''.$langs->trans("Ref").''.$langs->trans("Qty").''.$langs->trans("BuyingPrice").''.$langs->trans("UnitPrice").' 
'.img_object($langs->trans("ShowCompany"),'company').' '.$objp->nom.''.$objp->ref_fourn.''; - print $objp->quantity; - print ''; - print $objp->price?price($objp->price):""; - print ''; - print $objp->quantity?price($objp->price / $objp->quantity):" "; - print ''; - if ($user->rights->produit->creer) { - print ''.img_edit().""; - print ''; - print img_disable($langs->trans("Remove")).''; - } - - print '
'; + $product = new Product($db); + if ($_GET["ref"]) $result = $product->fetch('',$_GET["ref"]); + if ($_GET["id"]) $result = $product->fetch($_GET["id"]); + llxHeader("","",$langs->trans("CardProduct".$product->type)); + } + + if ( $result ) + { + + if ($_GET["action"] <> 'edit' && $_GET["action"] <> 're-edit') + { + /* + * En mode visu + */ + + $head=product_prepare_head($product, $user); + $titre=$langs->trans("CardProduct".$product->type); + dolibarr_fiche_head($head, 'suppliers', $titre); + + + print ''; + + // Reference + print ''; + print ''; + print ''; + + // Libelle + print ''; + + // Prix + print ''; + + // Statut + print ''; + + print '
'.$langs->trans("Ref").''; + $product->load_previous_next_ref(); + $previous_ref = $product->ref_previous?''.img_previous().'':''; + $next_ref = $product->ref_next?''.img_next().'':''; + if ($previous_ref || $next_ref) print '
'; + print ''.$product->ref.''; + if ($previous_ref || $next_ref) print ''.$previous_ref.''.$next_ref.'
'; + print '
'.$langs->trans("Label").''.$product->libelle.'
'.$langs->trans("SellingPrice").''.price($product->price).'
'.$langs->trans("Status").''; + print $product->getLibStatut(2); + print '
'; + + print "\n"; + + if ($mesg) print($mesg); + + + // Formulaire ajout prix + if ($_GET["action"] == 'add_price' && $user->rights->produit->creer) + { + $langs->load("suppliers"); + + if ($_GET["id_fourn"]) { + print_fiche_titre($langs->trans("ChangeSupplierPrice")); + } else { + print_fiche_titre($langs->trans("AddSupplierPrice")); + } + print ''; + print ''; + print ''; + + if ($_GET["id_fourn"]) { + print ''; + $product->fetch_fourn_data($_GET["id_fourn"]); + print ''; + } else { + print ''; + print ''; + } + + print ''; + $quantity = $_GET["qty"] ? $_GET["qty"] : "1"; + print ''; + print ''; + print ''; + + print ''; + print ''; + print '
'.$langs->trans("Supplier").''; + $html=new Form($db); + $html->select_societes('','id_fourn','fournisseur=1'); + print '
'.$langs->trans("Ref").''; + print ''; + print '
'.$langs->trans("Qty").''.$langs->trans("Price").'
 '; + print '
'; + } + + /* ************************************************************************** */ + /* */ + /* Barre d'action */ + /* */ + /* ************************************************************************** */ + + print "\n
\n"; + + if ($_GET["action"] != 'add_price') { + + if ($user->rights->produit->creer) + { + print ''; + print $langs->trans("AddSupplier").''; + } + + } + + print "\n
\n"; + print '
'; + + + if ($user->rights->fournisseur->lire) { + // Titre liste des fournisseurs + print ''; + if ($product->isproduct()) $nblignefour=4; + else $nblignefour=4; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + // Liste des fournisseurs + $sql = "SELECT s.nom, s.idp, pf.ref_fourn, pfp.price, pfp.quantity"; + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."product_fournisseur as pf"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp"; + $sql.= " ON pf.fk_soc = pfp.fk_soc AND pf.fk_product = pfp.fk_product"; + $sql.= " WHERE pf.fk_soc = s.idp AND pf.fk_product = ".$product->id; + $sql.= " ORDER BY lower(s.nom), pfp.quantity"; + + $resql=""; + $resql=$db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + + $var=True; + while ($i < $num) + { + $objp = $db->fetch_object($resql); + $var=!$var; + + print ""; + print ''; + + // Fournisseur + print ''; + + // Quantité + print ''; + + // Prix quantité + print ''; + + // Prix unitaire + print ''; + + // Modifier-Supprimer + print ''; + + print ''; + + $i++; + } + + $db->free($resql); + } + else { + dolibarr_print_error($db); + } + + print '
'; + print $langs->trans("Suppliers").''.$langs->trans("Ref").''.$langs->trans("Qty").''.$langs->trans("BuyingPrice").''.$langs->trans("UnitPrice").' 
'.img_object($langs->trans("ShowCompany"),'company').' '.$objp->nom.''.$objp->ref_fourn.''; + print $objp->quantity; + print ''; + print $objp->price?price($objp->price):""; + print ''; + print $objp->quantity?price($objp->price / $objp->quantity):" "; + print ''; + if ($user->rights->produit->creer) { + print ''.img_edit().""; + print ''; + print img_disable($langs->trans("Remove")).''; + } + + print '
'; + } + } } - } -} } else { - print $langs->trans("ErrorUnknown"); + print $langs->trans("ErrorUnknown"); }