From c9113458d9fae8bb729c66a9e652bbbb95fdaae1 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 25 Aug 2012 03:28:30 +0200 Subject: [PATCH] New: [ task #498 ] part 3 --- htdocs/comm/propal.php | 225 +++++++++------- htdocs/comm/propal/class/propal.class.php | 1 - htdocs/commande/fiche.php | 80 +++--- htdocs/compta/facture.php | 210 ++++++++------- .../facture/class/facture-rec.class.php | 66 ++--- htdocs/compta/facture/class/facture.class.php | 8 +- htdocs/compta/facture/fiche-rec.php | 245 ++++++++++-------- htdocs/core/ajax/price.php | 4 +- htdocs/core/class/commonobject.class.php | 15 +- htdocs/core/class/html.form.class.php | 6 +- htdocs/core/tpl/objectline_add.tpl.php | 85 ++++-- htdocs/core/tpl/objectline_edit.tpl.php | 60 +++-- htdocs/core/tpl/objectline_view.tpl.php | 2 +- htdocs/core/tpl/originproductline.tpl.php | 2 +- htdocs/fourn/commande/fiche.php | 20 +- .../install/mysql/migration/3.2.0-3.3.0.sql | 1 + .../mysql/tables/llx_facturedet_rec.sql | 52 ++-- 17 files changed, 623 insertions(+), 459 deletions(-) diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 4fb76387e61..8d11fbc7e94 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -140,7 +140,7 @@ if ($action == 'confirm_clone' && $confirm == 'yes') } // Suppression de la propale -else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->propale->supprimer) +else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->propal->supprimer) { $result=$object->delete($user); if ($result > 0) @@ -156,7 +156,7 @@ else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->prop } // Remove line -else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->propale->creer) +else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->propal->creer) { $result = $object->deleteline($lineid); // reorder lines @@ -183,7 +183,7 @@ else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights-> } // Validation -else if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->propale->valider) +else if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->propal->valider) { $result=$object->valid($user); if ($result >= 0) @@ -211,7 +211,7 @@ else if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->pr } } -else if ($action == 'setdate' && $user->rights->propale->creer) +else if ($action == 'setdate' && $user->rights->propal->creer) { $datep=dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); @@ -227,37 +227,37 @@ else if ($action == 'setdate' && $user->rights->propale->creer) if ($result < 0) dol_print_error($db,$object->error); } } -else if ($action == 'setecheance' && $user->rights->propale->creer) +else if ($action == 'setecheance' && $user->rights->propal->creer) { $result=$object->set_echeance($user,dol_mktime(12, 0, 0, $_POST['echmonth'], $_POST['echday'], $_POST['echyear'])); if ($result < 0) dol_print_error($db,$object->error); } -else if ($action == 'setdate_livraison' && $user->rights->propale->creer) +else if ($action == 'setdate_livraison' && $user->rights->propal->creer) { $result=$object->set_date_livraison($user,dol_mktime(12, 0, 0, $_POST['liv_month'], $_POST['liv_day'], $_POST['liv_year'])); if ($result < 0) dol_print_error($db,$object->error); } // Positionne ref client -else if ($action == 'set_ref_client' && $user->rights->propale->creer) +else if ($action == 'set_ref_client' && $user->rights->propal->creer) { $object->set_ref_client($user, $_POST['ref_client']); } -else if ($action == 'setnote_public' && $user->rights->propale->creer) +else if ($action == 'setnote_public' && $user->rights->propal->creer) { $result=$object->update_note_public(dol_html_entity_decode(GETPOST('note_public'), ENT_QUOTES)); if ($result < 0) dol_print_error($db,$object->error); } -else if ($action == 'setnote' && $user->rights->propale->creer) +else if ($action == 'setnote' && $user->rights->propal->creer) { $result=$object->update_note(dol_html_entity_decode(GETPOST('note'), ENT_QUOTES)); if ($result < 0) dol_print_error($db,$object->error); } // Create proposal -else if ($action == 'add' && $user->rights->propale->creer) +else if ($action == 'add' && $user->rights->propal->creer) { $object->socid=$socid; $object->fetch_thirdparty(); @@ -397,13 +397,13 @@ else if ($action == 'add' && $user->rights->propale->creer) } // Classify billed -else if ($action == 'classifybilled' && $user->rights->propale->cloturer) +else if ($action == 'classifybilled' && $user->rights->propal->cloturer) { $object->cloture($user, 4, ''); } // Reopen proposal -else if ($action == 'confirm_reopen' && $user->rights->propale->cloturer && ! GETPOST('cancel')) +else if ($action == 'confirm_reopen' && $user->rights->propal->cloturer && ! GETPOST('cancel')) { // prevent browser refresh from reopening proposal several times if ($object->statut==2 || $object->statut==3) @@ -413,7 +413,7 @@ else if ($action == 'confirm_reopen' && $user->rights->propale->cloturer && ! GE } // Close proposal -else if ($action == 'setstatut' && $user->rights->propale->cloturer && ! GETPOST('cancel')) +else if ($action == 'setstatut' && $user->rights->propal->cloturer && ! GETPOST('cancel')) { if (! GETPOST('statut')) { @@ -597,7 +597,7 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G } // Go back to draft -if ($action == 'modif' && $user->rights->propale->creer) +if ($action == 'modif' && $user->rights->propal->creer) { $object->set_draft($user); @@ -615,7 +615,7 @@ if ($action == 'modif' && $user->rights->propale->creer) if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); } -else if ($action == "setabsolutediscount" && $user->rights->propale->creer) +else if ($action == "setabsolutediscount" && $user->rights->propal->creer) { if ($_POST["remise_id"]) { @@ -631,7 +631,7 @@ else if ($action == "setabsolutediscount" && $user->rights->propale->creer) } //Ajout d'une ligne produit dans la propale -else if ($action == "addline" && $user->rights->propale->creer) +else if ($action == "addline" && $user->rights->propal->creer) { $idprod=GETPOST('idprod', 'int'); @@ -842,84 +842,131 @@ else if ($action == "addline" && $user->rights->propale->creer) } // Mise a jour d'une ligne dans la propale -else if ($action == 'updateligne' && $user->rights->propale->creer && GETPOST('save') == $langs->trans("Save")) +else if ($action == 'updateligne' && $user->rights->propal->creer && GETPOST('save') == $langs->trans("Save")) { // Define info_bits $info_bits=0; - if (preg_match('/\*/',$_POST['tva_tx'])) $info_bits |= 0x01; + if (preg_match('/\*/', GETPOST('tva_tx'))) $info_bits |= 0x01; + + // Clean parameters + $description=dol_htmlcleanlastbr(GETPOST('product_desc')); // Define vat_rate - $vat_rate=$_POST['tva_tx']; + $vat_rate=GETPOST('tva_tx'); $vat_rate=str_replace('*','',$vat_rate); $localtax1_rate=get_localtax($vat_rate,1,$object->client); $localtax2_rate=get_localtax($vat_rate,2,$object->client); - $pu_ht=GETPOST('pu')?GETPOST('pu'):GETPOST('subprice'); + $pu_ht=GETPOST('price_ht'); + + // Add buying price + $fournprice=(GETPOST('fournprice')?GETPOST('fournprice'):''); + $buyingprice=(GETPOST('buying_price')?GETPOST('buying_price'):''); // Define special_code for special lines $special_code=0; - if (empty($_POST['qty'])) $special_code=3; + if (! GETPOST('qty')) $special_code=3; - // On verifie que le prix minimum est respecte - $productid = $_POST['productid'] ; - if ($productid) + // Check minimum price + $productid = GETPOST('productid', 'int') ; + if (! empty($productid)) { $product = new Product($db); $res=$product->fetch($productid); + + $type=$product->type; + $price_min = $product->price_min; - if ($conf->global->PRODUIT_MULTIPRICES && $object->client->price_level) $price_min = $product->multiprices_min[$object->client->price_level]; + if (! empty($conf->global->PRODUIT_MULTIPRICES) && ! empty($object->client->price_level)) + $price_min = $product->multiprices_min[$object->client->price_level]; + + $label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label'):''); + + if ($price_min && (price2num($pu_ht)*(1-price2num(GETPOST('remise_percent'))/100) < price2num($price_min))) + { + setEventMessage($langs->trans("CantBeLessThanMinPrice", price2num($price_min,'MU')).getCurrencySymbol($conf->currency), 'errors'); + $error++; + } } - if ($productid && $price_min && (price2num($pu_ht)*(1-price2num($_POST['remise_percent'])/100) < price2num($price_min))) - { - $mesg = $langs->trans("CantBeLessThanMinPrice",price2num($price_min,'MU').' '.$langs->trans("Currency".$conf->currency)); - setEventMessage($mesg, 'errors'); + else + { + $type = GETPOST('type'); + $label = (GETPOST('product_label') ? GETPOST('product_label'):''); + + // Check parameters + if (GETPOST('type') < 0) { + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")), 'errors'); + $error++; + } } - else + + if (! $error) { $result = $object->updateline( - $_POST['lineid'], - $pu_ht, - $_POST['qty'], - $_POST['remise_percent'], - $vat_rate, - $localtax1_rate, - $localtax2_rate, - $_POST['desc'], - 'HT', - $info_bits, - $special_code, - $_POST['fk_parent_line'], - 0, - GETPOST('fournprice'), - GETPOST('buying_price') + GETPOST('lineid'), + $pu_ht, + GETPOST('qty'), + GETPOST('remise_percent'), + $vat_rate, + $localtax1_rate, + $localtax2_rate, + $description, + 'HT', + $info_bits, + $special_code, + GETPOST('fk_parent_line'), + 0, + $fournprice, + $buying_price, + $label ); - // Define output language - $outputlangs = $langs; - $newlang=''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id']; - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; - if (! empty($newlang)) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($newlang); - } - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { - $ret=$object->fetch($id); // Reload to get new records - propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); + if ($result >= 0) + { + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + // Define output language + $outputlangs = $langs; + $newlang=''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id']; + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } - unset($_POST['qty']); - unset($_POST['type']); - unset($_POST['np_price']); - unset($_POST['dp_desc']); - unset($_POST['np_tva_tx']); - unset($_POST['np_buying_price']); + $ret=$object->fetch($id); // Reload to get new records + propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); + } + + unset($_POST['qty']); + unset($_POST['type']); + unset($_POST['productid']); + unset($_POST['remise_percent']); + unset($_POST['price_ht']); + unset($_POST['price_ttc']); + unset($_POST['tva_tx']); + unset($_POST['product_ref']); + unset($_POST['product_label']); + unset($_POST['product_desc']); + unset($_POST['fournprice']); + unset($_POST['buying_price']); + } + else + { + setEventMessage($object->error, 'errors'); } } } +else if ($action == 'updateligne' && $user->rights->propal->creer && GETPOST('cancel') == $langs->trans('Cancel')) +{ + Header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // Pour reaffichage de la fiche en cours d'edition + exit; +} + // Generation doc (depuis lien ou depuis cartouche doc) -else if ($action == 'builddoc' && $user->rights->propale->creer) +else if ($action == 'builddoc' && $user->rights->propal->creer) { if (GETPOST('model')) { @@ -950,7 +997,7 @@ else if ($action == 'builddoc' && $user->rights->propale->creer) } // Remove file in doc form -else if ($action == 'remove_file' && $user->rights->propale->creer) +else if ($action == 'remove_file' && $user->rights->propal->creer) { if ($object->id > 0) { @@ -966,41 +1013,41 @@ else if ($action == 'remove_file' && $user->rights->propale->creer) } // Set project -else if ($action == 'classin' && $user->rights->propale->creer) +else if ($action == 'classin' && $user->rights->propal->creer) { $object->setProject($_POST['projectid']); } // Delai de livraison -else if ($action == 'setavailability' && $user->rights->propale->creer) +else if ($action == 'setavailability' && $user->rights->propal->creer) { $result = $object->availability($_POST['availability_id']); } // Origine de la propale -else if ($action == 'setdemandreason' && $user->rights->propale->creer) +else if ($action == 'setdemandreason' && $user->rights->propal->creer) { $result = $object->demand_reason($_POST['demand_reason_id']); } // Conditions de reglement -else if ($action == 'setconditions' && $user->rights->propale->creer) +else if ($action == 'setconditions' && $user->rights->propal->creer) { $result = $object->setPaymentTerms(GETPOST('cond_reglement_id','int')); } -else if ($action == 'setremisepercent' && $user->rights->propale->creer) +else if ($action == 'setremisepercent' && $user->rights->propal->creer) { $result = $object->set_remise_percent($user, $_POST['remise_percent']); } -else if ($action == 'setremiseabsolue' && $user->rights->propale->creer) +else if ($action == 'setremiseabsolue' && $user->rights->propal->creer) { $result = $object->set_remise_absolue($user, $_POST['remise_absolue']); } // Mode de reglement -else if ($action == 'setmode' && $user->rights->propale->creer) +else if ($action == 'setmode' && $user->rights->propal->creer) { $result = $object->setPaymentMethods(GETPOST('mode_reglement_id','int')); } @@ -1009,7 +1056,7 @@ else if ($action == 'setmode' && $user->rights->propale->creer) * Ordonnancement des lignes */ -else if ($action == 'up' && $user->rights->propale->creer) +else if ($action == 'up' && $user->rights->propal->creer) { $object->line_up(GETPOST('rowid')); @@ -1029,7 +1076,7 @@ else if ($action == 'up' && $user->rights->propale->creer) exit; } -else if ($action == 'down' && $user->rights->propale->creer) +else if ($action == 'down' && $user->rights->propal->creer) { $object->line_down(GETPOST('rowid')); @@ -1049,7 +1096,7 @@ else if ($action == 'down' && $user->rights->propale->creer) exit; } -if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->propale->creer) +if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->propal->creer) { if ($action == 'addcontact') { @@ -1228,7 +1275,7 @@ print ''; if ($action != 'refclient' && ! empty($object->brouillon)) print ''.img_edit($langs->trans('Modify')).''; print ''; print ''; -if ($user->rights->propale->creer && $action == 'refclient') +if ($user->rights->propal->creer && $action == 'refclient') { print '
'; print ''; @@ -1454,7 +1501,7 @@ if (! empty($conf->projet->enabled)) print ''; print ''; - if ($user->rights->propale->creer) + if ($user->rights->propal->creer) { if ($action != 'classify') print ''; print '
'; print $langs->trans('Project').''.img_edit($langs->transnoentitiesnoconv('SetProject')).'
'; @@ -1582,7 +1629,7 @@ if (! empty($object->lines)) $ret=$object->printObjectLines($action,$mysoc,$soc,$lineid,0,$hookmanager); // Form to add new line -if ($object->statut == 0 && $user->rights->propale->creer) +if ($object->statut == 0 && $user->rights->propal->creer) { if ($action != 'editline') { @@ -1641,20 +1688,20 @@ if ($action != 'presend') if ($action != 'statut' && $action <> 'editline') { // Validate - if ($object->statut == 0 && $user->rights->propale->valider) + if ($object->statut == 0 && $user->rights->propal->valider) { if (count($object->lines) > 0) print ''.$langs->trans('Validate').''; else print ''.$langs->trans('Validate').''; } // Edit - if ($object->statut == 1 && $user->rights->propale->creer) + if ($object->statut == 1 && $user->rights->propal->creer) { print ''.$langs->trans('Modify').''; } // ReOpen - if (($object->statut == 2 || $object->statut == 3) && $user->rights->propale->cloturer) + if (($object->statut == 2 || $object->statut == 3) && $user->rights->propal->cloturer) { print 'global->MAIN_JUMP_TAG)?'':'#reopen').'"'; print '>'.$langs->trans('ReOpen').''; @@ -1663,7 +1710,7 @@ if ($action != 'presend') // Send if ($object->statut == 1 || $object->statut == 2) { - if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->propale->propal_advance->send) + if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->propal->propal_advance->send) { print ''.$langs->trans('SendByMail').''; } @@ -1695,20 +1742,20 @@ if ($action != 'presend') } // Close - if ($object->statut == 1 && $user->rights->propale->cloturer) + if ($object->statut == 1 && $user->rights->propal->cloturer) { print 'global->MAIN_JUMP_TAG)?'':'#close').'"'; print '>'.$langs->trans('Close').''; } // Clone - if ($user->rights->propale->creer) + if ($user->rights->propal->creer) { print ''.$langs->trans("ToClone").''; } // Delete - if ($user->rights->propale->supprimer) + if ($user->rights->propal->supprimer) { print ''.$langs->trans('Delete').''; @@ -1732,8 +1779,8 @@ if ($action != 'presend') $filename=dol_sanitizeFileName($object->ref); $filedir=$conf->propal->dir_output . "/" . dol_sanitizeFileName($object->ref); $urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id; - $genallowed=$user->rights->propale->creer; - $delallowed=$user->rights->propale->supprimer; + $genallowed=$user->rights->propal->creer; + $delallowed=$user->rights->propal->supprimer; $var=true; diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 4cace6ae58c..83685ffac06 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -1130,7 +1130,6 @@ class Propal extends CommonObject $line->ref = $objp->product_ref; // TODO deprecated $line->product_ref = $objp->product_ref; $line->libelle = $objp->product_label; // TODO deprecated - $line->label = $objp->product_label; // TODO deprecated $line->product_label = $objp->product_label; $line->product_desc = $objp->product_desc; // Description produit $line->fk_product_type = $objp->fk_product_type; diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index b06a05b5ac4..4ea2e484a2f 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -37,10 +37,11 @@ require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/order.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; +if (! empty($conf->propal->enabled)) + require DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; if (! empty($conf->projet->enabled)) { - require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; - require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php'; - require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; + require DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; + require DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php'; } $langs->load('orders'); @@ -60,7 +61,7 @@ $action=GETPOST('action','alpha'); $confirm=GETPOST('confirm','alpha'); $lineid=GETPOST('lineid','int'); $origin=GETPOST('origin','alpha'); -$originid=GETPOST('origin_id','int'); +$originid=(GETPOST('originid','int')?GETPOST('originid','int'):GETPOST('origin_id','int')); // For backward compatibility $mesg = GETPOST('mesg'); @@ -218,7 +219,7 @@ else if ($action == 'add' && $user->rights->commande->creer) $object->contactid = GETPOST('contactidp'); // If creation from another object of another module (Example: origin=propal, originid=1) - if ($origin && $originid) + if (! empty($origin) && ! empty($originid)) { // Parse element/subelement (ex: project_task) $element = $subelement = $origin; @@ -271,8 +272,9 @@ else if ($action == 'add' && $user->rights->commande->creer) for ($i=0;$i<$num;$i++) { - $desc=($lines[$i]->desc?$lines[$i]->desc:$lines[$i]->libelle); - $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0); + $label=(! empty($lines[$i]->label)?$lines[$i]->label:''); + $desc=(! empty($lines[$i]->desc)?$lines[$i]->desc:$lines[$i]->libelle); + $product_type=(! empty($lines[$i]->product_type)?$lines[$i]->product_type:0); // Dates // TODO mutualiser @@ -309,7 +311,8 @@ else if ($action == 'add' && $user->rights->commande->creer) $lines[$i]->special_code, $fk_parent_line, $lines[$i]->fk_fournprice, - $lines[$i]->pa_ht + $lines[$i]->pa_ht, + $label ); if ($result < 0) @@ -760,7 +763,7 @@ else if ($action == 'updateligne' && $user->rights->commande->creer && GETPOST(' // Define info_bits $info_bits=0; - if (preg_match('/\*/',GETPOST('tva_tx'))) $info_bits |= 0x01; + if (preg_match('/\*/', GETPOST('tva_tx'))) $info_bits |= 0x01; // Define vat_rate $vat_rate=GETPOST('tva_tx'); @@ -773,19 +776,21 @@ else if ($action == 'updateligne' && $user->rights->commande->creer && GETPOST(' $buyingprice=(GETPOST('buying_price')?GETPOST('buying_price'):''); // Check minimum price - if (GETPOST('productid', 'int')) + $productid = GETPOST('productid', 'int'); + if (! empty($productid)) { - $productid = GETPOST('productid', 'int'); $product = new Product($db); $product->fetch($productid); + $type=$product->type; + $price_min = $product->price_min; - if ($conf->global->PRODUIT_MULTIPRICES && $object->client->price_level) + if (! empty($conf->global->PRODUIT_MULTIPRICES) && ! empty($object->client->price_level)) $price_min = $product->multiprices_min[$object->client->price_level]; $label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label'):''); - if ($price_min && (price2num($up_ht)*(1-price2num(GETPOST('remise_percent'))/100) < price2num($price_min))) + if ($price_min && (price2num($pu_ht)*(1-price2num(GETPOST('remise_percent'))/100) < price2num($price_min))) { setEventMessage($langs->trans("CantBeLessThanMinPrice", price2num($price_min,'MU')).getCurrencySymbol($conf->currency), 'errors'); $error++; @@ -798,7 +803,7 @@ else if ($action == 'updateligne' && $user->rights->commande->creer && GETPOST(' // Check parameters if (GETPOST('type') < 0) { - setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type"))); + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")), 'errors'); $error++; } } @@ -806,24 +811,24 @@ else if ($action == 'updateligne' && $user->rights->commande->creer && GETPOST(' if (! $error) { $result = $object->updateline( - GETPOST('lineid'), - $description, - $pu_ht, - GETPOST('qty'), - GETPOST('remise_percent'), - $vat_rate, - $localtax1_rate, - $localtax2_rate, - 'HT', - $info_bits, - $date_start, - $date_end, - $type, - GETPOST('fk_parent_line'), - 0, - $fournprice, - $buyingprice, - $label + GETPOST('lineid'), + $description, + $pu_ht, + GETPOST('qty'), + GETPOST('remise_percent'), + $vat_rate, + $localtax1_rate, + $localtax2_rate, + 'HT', + $info_bits, + $date_start, + $date_end, + $type, + GETPOST('fk_parent_line'), + 0, + $fournprice, + $buyingprice, + $label ); if ($result >= 0) @@ -1344,7 +1349,7 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G $soc = new Societe($db); if ($socid) $res=$soc->fetch($socid); - if ($origin && $originid) + if (! empty($origin) && ! empty($originid)) { // Parse element/subelement (ex: project_task) $element = $subelement = $origin; @@ -1419,7 +1424,6 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G print ''; print '' ."\n"; print ''; - print ''; print ''; print ''; @@ -1553,7 +1557,7 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G print ''; } - if (is_object($objectsrc)) + if (! empty($origin) && ! empty($originid) && is_object($objectsrc)) { // TODO for compatibility if ($origin == 'contrat') @@ -1593,7 +1597,7 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G } else { - if ($conf->global->PRODUCT_SHOW_WHEN_CREATE) + if (! empty($conf->global->PRODUCT_SHOW_WHEN_CREATE)) { /* * Services/produits predefinis @@ -1611,7 +1615,7 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G { print ''; // multiprix - if($conf->global->PRODUIT_MULTIPRICES) + if (! empty($conf->global->PRODUIT_MULTIPRICES)) print $form->select_produits('','idprod'.$i,'',$conf->product->limit_size,$soc->price_level); else print $form->select_produits('','idprod'.$i,'',$conf->product->limit_size); @@ -1634,7 +1638,7 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G // Show origin lines - if (is_object($objectsrc)) + if (! empty($origin) && ! empty($originid) && is_object($objectsrc)) { $title=$langs->trans('ProductsAndServices'); print_titre($title); diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index c49f9bce532..86be0bd2fc4 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -68,6 +68,8 @@ $search_ref=GETPOST('sf_ref')?GETPOST('sf_ref','alpha'):GETPOST('search_ref','al $search_societe=GETPOST('search_societe','alpha'); $search_montant_ht=GETPOST('search_montant_ht','alpha'); $search_montant_ttc=GETPOST('search_montant_ttc','alpha'); +$origin=GETPOST('origin','alpha'); +$originid=(GETPOST('originid','int')?GETPOST('originid','int'):GETPOST('origin_id','int')); // For backward compatibility //PDF $hidedetails = (GETPOST('hidedetails','int') ? GETPOST('hidedetails','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0)); @@ -791,7 +793,8 @@ else if ($action == 'add' && $user->rights->facture->creer) for ($i=0;$i<$num;$i++) { - $desc=($lines[$i]->desc?$lines[$i]->desc:$lines[$i]->libelle); + $label=(! empty($lines[$i]->label)?$lines[$i]->label:''); + $desc=(! empty($lines[$i]->desc)?$lines[$i]->desc:$lines[$i]->libelle); if ($lines[$i]->subprice < 0) { @@ -862,7 +865,8 @@ else if ($action == 'add' && $user->rights->facture->creer) $lines[$i]->rowid, $fk_parent_line, $lines[$i]->fk_fournprice, - $lines[$i]->pa_ht + $lines[$i]->pa_ht, + $label ); if ($result > 0) @@ -1198,12 +1202,12 @@ else if ($action == 'updateligne' && $user->rights->facture->creer && $_POST['sa $date_end=''; $date_start=dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), GETPOST('date_startsec'), GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear')); $date_end=dol_mktime(GETPOST('date_endhour'), GETPOST('date_endmin'), GETPOST('date_endsec'), GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear')); - $description=dol_htmlcleanlastbr($_POST['desc']); - $up_ht=GETPOST('pu')?GETPOST('pu'):GETPOST('subprice'); + $description=dol_htmlcleanlastbr(GETPOST('product_desc')); + $pu_ht=GETPOST('price_ht'); // Define info_bits $info_bits=0; - if (preg_match('/\*/',$_POST['tva_tx'])) $info_bits |= 0x01; + if (preg_match('/\*/', GETPOST('tva_tx'))) $info_bits |= 0x01; // Define vat_rate $vat_rate=$_POST['tva_tx']; @@ -1211,85 +1215,103 @@ else if ($action == 'updateligne' && $user->rights->facture->creer && $_POST['sa $localtax1_rate=get_localtax($vat_rate,1,$object->client); $localtax2_rate=get_localtax($vat_rate,2,$object->client); - // ajout prix d'achat - $fk_fournprice = $_POST['fournprice']; - if ( ! empty($_POST['buying_price']) ) - $pa_ht = $_POST['buying_price']; - else - $pa_ht = null; + // Add buying price + $fournprice=(GETPOST('fournprice')?GETPOST('fournprice'):''); + $buyingprice=(GETPOST('buying_price')?GETPOST('buying_price'):''); - // Check parameters - if (! GETPOST('productid') && GETPOST("type") < 0) - { - $mesgs[] = '
'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")).'
'; - $result = -1 ; - } // Check minimum price - if (GETPOST('productid')) + $productid = GETPOST('productid', 'int'); + if (! empty($productid)) { - $productid = GETPOST('productid'); $product = new Product($db); $product->fetch($productid); + $type=$product->type; + $price_min = $product->price_min; - if ($conf->global->PRODUIT_MULTIPRICES && $object->client->price_level) $price_min = $product->multiprices_min[$object->client->price_level]; + if (! empty($conf->global->PRODUIT_MULTIPRICES) && ! empty($object->client->price_level)) + $price_min = $product->multiprices_min[$object->client->price_level]; + + $label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label'):''); + + if ($price_min && (price2num($pu_ht)*(1-price2num(GETPOST('remise_percent'))/100) < price2num($price_min))) + { + setEventMessage($langs->trans("CantBeLessThanMinPrice", price2num($price_min,'MU')).getCurrencySymbol($conf->currency), 'errors'); + $error++; + } } - if ($object->type!=2 && $price_min && GETPOST('productid') && (price2num($up_ht)*(1-price2num(GETPOST('remise_percent'))/100) < price2num($price_min))) - { - //print "CantBeLessThanMinPrice ".$up_ht." - ".GETPOST('remise_percent')." - ".$product->price_min; - $mesgs[] = '
'.$langs->trans("CantBeLessThanMinPrice",price2num($price_min,'MU').' '.$langs->trans("Currency".$conf->currency)).'
'; - $result=-1; + else + { + $type = GETPOST('type'); + $label = (GETPOST('product_label') ? GETPOST('product_label'):''); + + // Check parameters + if (GETPOST('type') < 0) { + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")), 'errors'); + $error++; + } } - // Define params - if (GETPOST('productid')) $type=$product->type; - else $type=GETPOST("type"); + // Update line + if (! $error) + { + $result = $object->updateline( + GETPOST('lineid'), + $description, + $pu_ht, + GETPOST('qty'), + GETPOST('remise_percent'), + $date_start, + $date_end, + $vat_rate, + $localtax1_rate, + $localtax2_rate, + 'HT', + $info_bits, + $type, + GETPOST('fk_parent_line'), + 0, + $fournprice, + $buyingprice, + $label + ); - // Update line - if ($result >= 0) - { - $result = $object->updateline( - GETPOST('lineid'), - $description, - $up_ht, - GETPOST('qty'), - GETPOST('remise_percent'), - $date_start, - $date_end, - $vat_rate, - $localtax1_rate, - $localtax2_rate, - 'HT', - $info_bits, - $type, - GETPOST('fk_parent_line'), - 0, - $fk_fournprice, - $pa_ht - ); + if ($result >= 0) + { + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + // Define output language + $outputlangs = $langs; + $newlang=''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } - // Define output language - $outputlangs = $langs; - $newlang=''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; - if (! empty($newlang)) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($newlang); - } - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { - $ret=$object->fetch($id); // Reload to get new records - facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); + $ret=$object->fetch($id); // Reload to get new records + facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); + } - unset($_POST['qty']); - unset($_POST['type']); - unset($_POST['np_price']); - unset($_POST['dp_desc']); - unset($_POST['np_tva_tx']); - unset($_POST['np_buying_price']); - } + unset($_POST['qty']); + unset($_POST['type']); + unset($_POST['productid']); + unset($_POST['remise_percent']); + unset($_POST['price_ht']); + unset($_POST['price_ttc']); + unset($_POST['tva_tx']); + unset($_POST['product_ref']); + unset($_POST['product_label']); + unset($_POST['product_desc']); + unset($_POST['fournprice']); + unset($_POST['buying_price']); + } + else + { + setEventMessage($object->error, 'errors'); + } } } @@ -1691,11 +1713,11 @@ if ($action == 'create') $soc = new Societe($db); if ($socid) $res=$soc->fetch($socid); - if (GETPOST('origin') && GETPOST('originid')) + if (! empty($origin) && ! empty($originid)) { // Parse element/subelement (ex: project_task) - $element = $subelement = GETPOST('origin'); - if (preg_match('/^([^_]+)_([^_]+)/i',GETPOST('origin'),$regs)) + $element = $subelement = $origin; + if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs)) { $element = $regs[1]; $subelement = $regs[2]; @@ -1703,7 +1725,7 @@ if ($action == 'create') if ($element == 'project') { - $projectid=GETPOST('originid'); + $projectid=$originid; } else { @@ -1717,19 +1739,19 @@ if ($action == 'create') $classname = ucfirst($subelement); $objectsrc = new $classname($db); - $objectsrc->fetch(GETPOST('originid')); + $objectsrc->fetch($originid); if (empty($objectsrc->lines) && method_exists($objectsrc,'fetch_lines')) $objectsrc->fetch_lines(); $objectsrc->fetch_thirdparty(); - $projectid = (!empty($objectsrc->fk_project)?$objectsrc->fk_project:''); - $ref_client = (!empty($objectsrc->ref_client)?$objectsrc->ref_client:''); - $ref_int = (!empty($objectsrc->ref_int)?$objectsrc->ref_int:''); + $projectid = (! empty($objectsrc->fk_project)?$objectsrc->fk_project:''); + $ref_client = (! empty($objectsrc->ref_client)?$objectsrc->ref_client:''); + $ref_int = (! empty($objectsrc->ref_int)?$objectsrc->ref_int:''); $soc = $objectsrc->client; - $cond_reglement_id = (!empty($objectsrc->cond_reglement_id)?$objectsrc->cond_reglement_id:(!empty($soc->cond_reglement_id)?$soc->cond_reglement_id:1)); - $mode_reglement_id = (!empty($objectsrc->mode_reglement_id)?$objectsrc->mode_reglement_id:(!empty($soc->mode_reglement_id)?$soc->mode_reglement_id:0)); - $remise_percent = (!empty($objectsrc->remise_percent)?$objectsrc->remise_percent:(!empty($soc->remise_percent)?$soc->remise_percent:0)); - $remise_absolue = (!empty($objectsrc->remise_absolue)?$objectsrc->remise_absolue:(!empty($soc->remise_absolue)?$soc->remise_absolue:0)); + $cond_reglement_id = (! empty($objectsrc->cond_reglement_id)?$objectsrc->cond_reglement_id:(! empty($soc->cond_reglement_id)?$soc->cond_reglement_id:1)); + $mode_reglement_id = (! empty($objectsrc->mode_reglement_id)?$objectsrc->mode_reglement_id:(! empty($soc->mode_reglement_id)?$soc->mode_reglement_id:0)); + $remise_percent = (! empty($objectsrc->remise_percent)?$objectsrc->remise_percent:(! empty($soc->remise_percent)?$soc->remise_percent:0)); + $remise_absolue = (! empty($objectsrc->remise_absolue)?$objectsrc->remise_absolue:(! empty($soc->remise_absolue)?$soc->remise_absolue:0)); $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0; } } @@ -1744,7 +1766,7 @@ if ($action == 'create') $absolute_discount=$soc->getAvailableDiscounts(); - if ($conf->use_javascript_ajax) + if (! empty($conf->use_javascript_ajax)) { print ajax_combobox('fac_replacement'); print ajax_combobox('fac_avoir'); @@ -1757,8 +1779,8 @@ if ($action == 'create') print ''; print ''; print ''; - print ''; - print ''; + print ''; + print ''; print ''; @@ -1766,7 +1788,7 @@ if ($action == 'create') print ''; // Factures predefinies - if (empty($_GET['propalid']) && empty($_GET['commandeid']) && empty($_GET['contratid']) && empty($_GET['originid'])) + if (empty($origin) && empty($originid)) { $sql = 'SELECT r.rowid, r.titre, r.total_ttc'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facture_rec as r'; @@ -1787,7 +1809,7 @@ if ($action == 'create') { $objp = $db->fetch_object($resql); print ''; $i++; } @@ -1997,23 +2019,23 @@ if ($action == 'create') print ''; // Private note - if (! $user->societe_id) + if (empty($user->societe_id)) { print ''; print ''; print ''; } - if (is_object($objectsrc)) + if (! empty($origin) && ! empty($originid) && is_object($objectsrc)) { // TODO for compatibility - if ($_GET['origin'] == 'contrat') + if ($origin == 'contrat') { // Calcul contrat->price (HT), contrat->total (TTC), contrat->tva $objectsrc->remise_absolue=$remise_absolue; @@ -2051,7 +2073,7 @@ if ($action == 'create') else { // Show deprecated optional form to add product line here - if ($conf->global->PRODUCT_SHOW_WHEN_CREATE) + if (! empty($conf->global->PRODUCT_SHOW_WHEN_CREATE)) { print '
'.$langs->trans('Ref').''.$langs->trans('Draft').'
'.$langs->trans('NotePrivate').''; print '
'; @@ -2113,7 +2135,7 @@ if ($action == 'create') print "\n"; // Show origin lines - if (is_object($objectsrc)) + if (! empty($origin) && ! empty($originid) && is_object($objectsrc)) { print '
'; diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php index 7eef830a887..be13100c539 100644 --- a/htdocs/compta/facture/class/facture-rec.class.php +++ b/htdocs/compta/facture/class/facture-rec.class.php @@ -1,8 +1,8 @@ - * Copyright (C) 2004-2012 Laurent Destailleur - * Copyright (C) 2009 Regis Houssin - * Copyright (C) 2010-2011 Juanjo Menent +/* Copyright (C) 2003-2005 Rodolphe Quiedeville + * Copyright (C) 2004-2012 Laurent Destailleur + * Copyright (C) 2009-2012 Regis Houssin + * Copyright (C) 2010-2011 Juanjo Menent * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -82,9 +82,9 @@ class FactureRec extends Facture * @param int $facid Id of source invoice * @return int <0 if KO, id of invoice if OK */ - function create($user,$facid) + function create($user, $facid) { - global $conf, $langs; + global $conf; $error=0; $now=dol_now(); @@ -92,13 +92,6 @@ class FactureRec extends Facture // Clean parameters $this->titre=trim($this->titre); - // Validate parameters - if (empty($this->titre)) - { - $this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Title")); - return -3; - } - $this->db->begin(); // Charge facture modele @@ -130,12 +123,12 @@ class FactureRec extends Facture $sql.= ", '".$facsrc->remise."'"; $sql.= ", '".$this->db->escape($this->note)."'"; $sql.= ", '".$user->id."'"; - $sql.= ", ".($facsrc->fk_project?"'".$facsrc->fk_project."'":"null"); + $sql.= ", ".(! empty($facsrc->fk_project)?"'".$facsrc->fk_project."'":"null"); $sql.= ", '".$facsrc->cond_reglement_id."'"; $sql.= ", '".$facsrc->mode_reglement_id."'"; $sql.= ")"; - if ( $this->db->query($sql) ) + if ($this->db->query($sql)) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."facture_rec"); @@ -159,7 +152,8 @@ class FactureRec extends Facture 0, $facsrc->lines[$i]->product_type, $facsrc->lines[$i]->rang, - $facsrc->lines[$i]->special_code + $facsrc->lines[$i]->special_code, + $facsrc->lines[$i]->label ); if ($result_insert < 0) @@ -257,23 +251,6 @@ class FactureRec extends Facture $this->modelpdf = $obj->model_pdf; $this->rang = $obj->rang; $this->special_code = $obj->special_code; - $this->commande_id = $obj->fk_commande; - - if ($this->commande_id) - { - $sql = "SELECT ref"; - $sql.= " FROM ".MAIN_DB_PREFIX."commande"; - $sql.= " WHERE rowid = ".$this->commande_id; - - $resqlcomm = $this->db->query($sql); - - if ($resqlcomm) - { - $objc = $this->db->fetch_object($resqlcomm); - $this->commande_ref = $objc->ref; - $this->db->free($resqlcomm); - } - } if ($this->statut == 0) $this->brouillon = 1; @@ -312,11 +289,11 @@ class FactureRec extends Facture */ function fetch_lines() { - $sql = 'SELECT l.rowid, l.fk_product, l.product_type, l.description, l.price, l.qty, l.tva_tx, '; + $sql = 'SELECT l.rowid, l.fk_product, l.product_type, l.label as custom_label, l.description, l.price, l.qty, l.tva_tx, '; $sql.= ' l.remise, l.remise_percent, l.subprice,'; $sql.= ' l.total_ht, l.total_tva, l.total_ttc,'; $sql.= ' l.rang, l.special_code,'; - $sql.= ' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as label, p.description as product_desc'; + $sql.= ' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facturedet_rec as l'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid'; $sql.= ' WHERE l.fk_facture = '.$this->id; @@ -333,12 +310,13 @@ class FactureRec extends Facture $line = new FactureLigne($this->db); $line->rowid = $objp->rowid; - $line->desc = $objp->description; // Description line - $line->product_type = $objp->product_type; // Type of line - $line->product_ref = $objp->product_ref; // Ref product - $line->libelle = $objp->label; // Label product - $line->product_label = $objp->product_label; - $line->product_desc = $objp->product_desc; // Description product + $line->label = $objp->custom_label; // Label line + $line->desc = $objp->description; // Description line + $line->product_type = $objp->product_type; // Type of line + $line->product_ref = $objp->product_ref; // Ref product + $line->libelle = $objp->product_label; // deprecated + $line->product_label = $objp->product_label; // Label product + $line->product_desc = $objp->product_desc; // Description product $line->fk_product_type = $objp->fk_product_type; // Type of product $line->qty = $objp->qty; $line->subprice = $objp->subprice; @@ -430,7 +408,7 @@ class FactureRec extends Facture * @param int $special_code Special code * @return int <0 if KO, Id of line if OK */ - function addline($facid, $desc, $pu_ht, $qty, $txtva, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0, $fk_remise_except='', $pu_ttc=0, $type=0, $rang=-1, $special_code=0) + function addline($facid, $desc, $pu_ht, $qty, $txtva, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0, $fk_remise_except='', $pu_ttc=0, $type=0, $rang=-1, $special_code=0, $label='') { dol_syslog("FactureRec::addline facid=$facid,desc=$desc,pu_ht=$pu_ht,qty=$qty,txtva=$txtva,fk_product=$fk_product,remise_percent=$remise_percent,date_start=$date_start,date_end=$date_end,ventil=$ventil,info_bits=$info_bits,fk_remise_except=$fk_remise_except,price_base_type=$price_base_type,pu_ttc=$pu_ttc,type=$type", LOG_DEBUG); include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; @@ -477,6 +455,7 @@ class FactureRec extends Facture $sql = "INSERT INTO ".MAIN_DB_PREFIX."facturedet_rec ("; $sql.= "fk_facture"; + $sql.= ", label"; $sql.= ", description"; $sql.= ", price"; $sql.= ", qty"; @@ -493,11 +472,12 @@ class FactureRec extends Facture $sql.= ", special_code"; $sql.= ") VALUES ("; $sql.= "'".$facid."'"; + $sql.= ", ".(! empty($label)?"'".$this->db->escape($label)."'":"null"); $sql.= ", '".$this->db->escape($desc)."'"; $sql.= ", ".price2num($pu_ht); $sql.= ", ".price2num($qty); $sql.= ", ".price2num($txtva); - $sql.= ", ".($fk_product?"'".$fk_product."'":"null"); + $sql.= ", ".(! empty($fk_product)?"'".$fk_product."'":"null"); $sql.= ", ".$product_type; $sql.= ", '".price2num($remise_percent)."'"; $sql.= ", '".price2num($pu_ht)."'"; diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 0ff49cd8f7e..fcd550e6734 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -411,7 +411,13 @@ class Facture extends CommonInvoice '','',0,0,'','HT',0, $_facrec->lines[$i]->product_type, $_facrec->lines[$i]->rang, - $_facrec->lines[$i]->special_code + $_facrec->lines[$i]->special_code, + '', + 0, + 0, + null, + 0, + $_facrec->lines[$i]->label ); if ( $result_insert < 0) diff --git a/htdocs/compta/facture/fiche-rec.php b/htdocs/compta/facture/fiche-rec.php index 9b16565678d..f23e16297b3 100644 --- a/htdocs/compta/facture/fiche-rec.php +++ b/htdocs/compta/facture/fiche-rec.php @@ -31,12 +31,12 @@ require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; $langs->load('bills'); // Security check -$facid=GETPOST('facid','int'); -$action=GETPOST("action"); +$id=(GETPOST('facid','int')?GETPOST('facid','int'):GETPOST('id','int')); +$action=GETPOST('action', 'alpha'); if ($user->societe_id) $socid=$user->societe_id; $objecttype = 'facture_rec'; if ($action == "create" || $action == "add") $objecttype = ''; -$result = restrictedArea($user, 'facture', $facid, $objecttype); +$result = restrictedArea($user, 'facture', $id, $objecttype); if ($page == -1) { @@ -51,6 +51,8 @@ $sortorder="DESC"; if ($sortfield == "") $sortfield="f.datef"; +$object = new FactureRec($db); + /* * Actions @@ -60,29 +62,37 @@ $sortfield="f.datef"; // Create predefined invoice if ($action == 'add') { - $facturerec = new FactureRec($db); - $facturerec->titre = $_POST["titre"]; - $facturerec->note = $_POST["comment"]; - - if ($facturerec->create($user,$facid) > 0) - { - $facid = $facturerec->id; - $action = ''; - } - else - { + if (! GETPOST('titre')) + { + setEventMessage($langs->trans("ErrorFieldRequired",$langs->trans("Title")), 'errors'); $action = "create"; - $mesg = '
'.$facturerec->error.'
'; + $error++; + } + + if (! $error) + { + $object->titre = GETPOST('titre', 'alpha'); + $object->note = GETPOST('comment'); + + if ($object->create($user, $id) > 0) + { + $id = $object->id; + $action = ''; + } + else + { + setEventMessage($object->error, 'errors'); + $action = "create"; + } } } // Suppression if ($action == 'delete' && $user->rights->facture->supprimer) { - $facrec = new FactureRec($db); - $facrec->fetch($facid); - $facrec->delete(); - $facid = 0 ; + $object->fetch($id); + $object->delete(); + $id = 0 ; } @@ -102,23 +112,21 @@ if ($action == 'create') { print_fiche_titre($langs->trans("CreateRepeatableInvoice")); - if ($mesg) print $mesg.'
'; + $invoice = new Facture($db); // Source invoice + $product_static = new Product($db); - $facture = new Facture($db); // Source invoice - $product_static=new Product($db); - - if ($facture->fetch($facid) > 0) + if ($invoice->fetch($id) > 0) { print '
'; print ''; print ''; - print ''; + print ''; print ''; - $facture->fetch_thirdparty(); + $invoice->fetch_thirdparty(); - print ''; + print ''; print ''; @@ -134,20 +142,20 @@ if ($action == 'create') print ""; print ""; print ""; - if ($conf->projet->enabled) + if (! empty($conf->projet->enabled)) { print ""; @@ -155,14 +163,15 @@ if ($action == 'create') print "
'.$langs->trans("Customer").''.$facture->client->getNomUrl(1).'
'.$langs->trans("Customer").''.$invoice->client->getNomUrl(1).''; //print $langs->trans("NotePrivate"); print '
".$langs->trans("Author")."".$user->getFullName($langs)."
".$langs->trans("PaymentConditions").""; - $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?facid='.$facture->id,$facture->cond_reglement_id,'none'); + $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$invoice->id, $invoice->cond_reglement_id, 'none'); print "
".$langs->trans("PaymentMode").""; - $form->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$facture->id,$facture->mode_reglement_id,'none'); + $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$invoice->id, $facture->mode_reglement_id, 'none'); print "
".$langs->trans("Project").""; - if ($facture->fk_project > 0) + if ($invoice->fk_project > 0) { $project = new Project($db); - $project->fetch($facture->fk_project); + $project->fetch($invoice->fk_project); print $project->title; } print "
"; - - print '
'; - if ($conf->service->enabled) { - print_titre($langs->trans("ProductsAndServices")); - } else { - print_titre($langs->trans("Products")); - } + + $title = $langs->trans("ProductsAndServices"); + if (empty($conf->service->enabled)) + $title = $langs->trans("Products"); + else if (empty($conf->product->enabled)) + $title = $langs->trans("Services"); + + print_titre($title); /* * Invoice lines @@ -170,7 +179,7 @@ if ($action == 'create') print ''; print ''; + // TODO not used if ($flag_different_price) { print '"; - print '\n"; print ''; diff --git a/htdocs/core/ajax/price.php b/htdocs/core/ajax/price.php index ba6ebe615e5..c1aab70882e 100644 --- a/htdocs/core/ajax/price.php +++ b/htdocs/core/ajax/price.php @@ -48,12 +48,12 @@ if (! empty($action) && isset($tva_tx)) $return=array(); $price=''; - if ($action == 'get_ttc' && isset($pu_ht) && $pu_ht != '') { + if ($action == 'get_ttc' && isset($pu_ht) && is_numeric($pu_ht) && $pu_ht != '') { $price = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU'); } - else if ($action == 'get_ht' && isset($pu_ttc) && $pu_ttc != '') { + else if ($action == 'get_ht' && isset($pu_ttc) && is_numeric($pu_ttc) && $pu_ttc != '') { $price = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU'); diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 70da921121b..fe66af1b39d 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -2697,7 +2697,7 @@ abstract class CommonObject { $var=!$var; - if (is_object($hookmanager) && ( ($line->product_type == 9 && ! empty($line->special_code)) || ! empty($line->fk_parent_line) ) ) + if (is_object($hookmanager) && (($line->product_type == 9 && ! empty($line->special_code)) || ! empty($line->fk_parent_line))) { if (empty($line->fk_parent_line)) { @@ -2745,14 +2745,14 @@ abstract class CommonObject $discount->fk_soc = $this->socid; $this->tpl['label'].= $discount->getNomUrl(0,'discount'); } - else if ($line->fk_product) + else if (! empty($line->fk_product)) { $productstatic = new Product($this->db); $productstatic->id = $line->fk_product; $productstatic->ref = $line->ref; $productstatic->type = $line->fk_product_type; $this->tpl['label'].= $productstatic->getNomUrl(1); - $this->tpl['label'].= $line->label?' - '.$line->label:''; + $this->tpl['label'].= ' - '.(! empty($line->label)?$line->label:$line->product_label); // Dates if ($line->product_type == 1 && ($date_start || $date_end)) { @@ -2770,7 +2770,7 @@ abstract class CommonObject } } - if ($line->desc) + if (! empty($line->desc)) { if ($line->desc == '(CREDIT_NOTE)') // TODO Not sure this is used for source object { @@ -2804,7 +2804,12 @@ abstract class CommonObject $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl')); foreach($dirtpls as $reldir) { - $res=@include dol_buildpath($reldir.'/originproductline.tpl.php'); + $tpl = dol_buildpath($reldir.'/originproductline.tpl.php'); + if (empty($conf->file->strict_mode)) { + $res=@include $tpl; + } else { + $res=include $tpl; // for debug + } if ($res) break; } } diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 9eb0d2b7e67..d32a30e5b0c 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -543,7 +543,7 @@ class Form global $db,$langs,$user,$conf; // If product & services are enabled or both disabled. - if ($forceall || ($conf->product->enabled && $conf->service->enabled) + if ($forceall || (! empty($conf->product->enabled) && ! empty($conf->service->enabled)) || (empty($conf->product->enabled) && empty($conf->service->enabled))) { if (empty($hidetext)) print $langs->trans("Type").': '; @@ -566,11 +566,11 @@ class Form print ''; //if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1); } - if (! $forceall && empty($conf->product->enabled) && $conf->service->enabled) + if (! $forceall && empty($conf->product->enabled) && ! empty($conf->service->enabled)) { print ''; } - if (! $forceall && $conf->product->enabled && empty($conf->service->enabled)) + if (! $forceall && ! empty($conf->product->enabled) && empty($conf->service->enabled)) { print ''; } diff --git a/htdocs/core/tpl/objectline_add.tpl.php b/htdocs/core/tpl/objectline_add.tpl.php index a7d5e582fa0..7b1ecddeaff 100644 --- a/htdocs/core/tpl/objectline_add.tpl.php +++ b/htdocs/core/tpl/objectline_add.tpl.php @@ -74,9 +74,12 @@ if (! empty($conf->margin->enabled)) { 'select_type' => 'type', 'product_ref' => 'value', 'product_label' => 'label2', + 'origin_label_cache' => 'label2', 'origin_desc_cache' => 'desc', 'price_ht' => 'price_ht', - 'price_ttc' => 'price_ttc' + 'origin_price_ht_cache' => 'price_ht', + 'price_ttc' => 'price_ttc', + 'origin_price_ttc_cache' => 'price_ttc' ), 'show' => array( 'update_label_area', @@ -107,6 +110,7 @@ if (! empty($conf->margin->enabled)) { | textwithtooltip($langs->trans('UpdateOriginalProductPrice'), $langs->trans('HelpUpdateOriginalProductPrice'),1,0,'','',3); ?> + @@ -121,7 +125,8 @@ if (! empty($conf->margin->enabled)) { echo ''; echo ' '; - echo ''; + echo ''; + echo ''; if (is_object($hookmanager)) { @@ -152,9 +157,15 @@ if (! empty($conf->margin->enabled)) { else echo $form->load_tva('tva_tx', (GETPOST('tva_tx')?GETPOST('tva_tx'):-1), $seller, $buyer); ?> - - - + + + /core/ajax/price.php', { 'action': 'get_ttc', 'pu_ht': $(this).val(), @@ -365,7 +390,12 @@ $(document).ready(function() { } }); - $('#price_ttc').onDelayedKeyup({ handler: function() { + $('#price_ttc').focusin(function() { + $('#price_base_type').html('TTC'); + }); + + $('#price_ttc').onDelayedKeyup({ + handler: function() { $.post('/core/ajax/price.php', { 'action': 'get_ht', 'pu_ttc': $(this).val(), @@ -388,16 +418,29 @@ $(document).ready(function() { }); $('#tva_tx').change(function() { - $.post('/core/ajax/price.php', { - 'action': 'get_ttc', - 'pu_ht': $('#price_ht').val(), - 'tva_tx': $(this).val() - }, - function(data) { - if (data && data.price.length > 0) { - $('#price_ttc').val(data.price); - } - }, 'json'); + if ($('#price_base_type').html() == 'HT') { + $.post('/core/ajax/price.php', { + 'action': 'get_ttc', + 'pu_ht': $('#price_ht').val(), + 'tva_tx': $(this).val() + }, + function(data) { + if (data && data.price.length > 0) { + $('#price_ttc').val(data.price); + } + }, 'json'); + } else if ($('#price_base_type').html() == 'TTC') { + $.post('/core/ajax/price.php', { + 'action': 'get_ht', + 'pu_ttc': $('#price_ttc').val(), + 'tva_tx': $(this).val() + }, + function(data) { + if (data && data.price.length > 0) { + $('#price_ht').val(data.price); + } + }, 'json'); + } }); }); diff --git a/htdocs/core/tpl/objectline_edit.tpl.php b/htdocs/core/tpl/objectline_edit.tpl.php index 4238ac8d09a..06b5a17bfc8 100644 --- a/htdocs/core/tpl/objectline_edit.tpl.php +++ b/htdocs/core/tpl/objectline_edit.tpl.php @@ -46,9 +46,11 @@ fk_product) && empty($line->label)) ? ' disabled="disabled"' : ''); ?>> + textwithtooltip($langs->trans('UpdateOriginalProductLabel'), $langs->trans('HelpUpdateOriginalProductLabel'),1,0,'','',3); ?> +
@@ -71,12 +73,12 @@ - - + +
'; - $sql = 'SELECT l.fk_product, l.product_type, l.description, l.qty, l.rowid, l.tva_tx,'; + $sql = 'SELECT l.fk_product, l.product_type, l.label as custom_label, l.description, l.qty, l.rowid, l.tva_tx,'; $sql.= ' l.fk_remise_except,'; $sql.= ' l.remise_percent, l.subprice, l.info_bits,'; $sql.= ' l.total_ht, l.total_tva, l.total_ttc,'; @@ -181,7 +190,7 @@ if ($action == 'create') $sql.= ' 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"; - $sql.= " WHERE l.fk_facture = ".$facture->id; + $sql.= " WHERE l.fk_facture = ".$invoice->id; $sql.= " ORDER BY l.rowid"; $result = $db->query($sql); @@ -193,7 +202,7 @@ if ($action == 'create') echo ''; if ($num) { - print ""; + print ''; print ''; print ''; print ''; @@ -217,7 +226,7 @@ if ($action == 'create') print ""; // Show product and description - $type=$objp->product_type?$objp->product_type:$objp->fk_product_type; + $type=(isset($objp->product_type)?$objp->product_type:$objp->fk_product_type); if ($objp->fk_product) { @@ -229,17 +238,17 @@ if ($action == 'create') $product_static->type=$objp->fk_product_type; $product_static->id=$objp->fk_product; $product_static->ref=$objp->ref; - $product_static->libelle=$objp->product_label; $text=$product_static->getNomUrl(1); - $text.= ' - '.$objp->product_label; - $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($objp->description)); + $text.= ' - '.(! empty($objp->custom_label)?$objp->custom_label:$objp->product_label); + $description=(! empty($conf->global->PRODUIT_DESC_IN_FORM)?'':dol_htmlentitiesbr($objp->description)); print $form->textwithtooltip($text,$description,3,'','',$i); // Show range - print_date_range($db->jdate($objp->date_start),$db->jdate($objp->date_end)); + print_date_range($db->jdate($objp->date_start), $db->jdate($objp->date_end)); // Add description in form - if ($conf->global->PRODUIT_DESC_IN_FORM) print ($objp->description && $objp->description!=$objp->product_label)?'
'.dol_htmlentitiesbr($objp->description):''; + if (! empty($conf->global->PRODUIT_DESC_IN_FORM)) + print (! empty($objp->description) && $objp->description!=$objp->product_label)?'
'.dol_htmlentitiesbr($objp->description):''; print ''; } @@ -250,17 +259,26 @@ if ($action == 'create') if ($type==1) $text = img_object($langs->trans('Service'),'service'); else $text = img_object($langs->trans('Product'),'product'); - print $text.' '.nl2br($objp->description); + + if (! empty($objp->custom_label)) { + + $text.= ' '.$objp->custom_label.''; + print $form->textwithtooltip($text,dol_htmlentitiesbr($objp->description),3,'','',$i); + + } else { + + print $text.' '.nl2br($objp->description); + } // Show range - print_date_range($db->jdate($objp->date_start),$db->jdate($objp->date_end)); + print_date_range($db->jdate($objp->date_start), $db->jdate($objp->date_end)); print "\n"; } - print ''; - print ''; + print ''; + print ''; if ($objp->remise_percent > 0) { print '\n"; @@ -270,7 +288,7 @@ if ($action == 'create') print ''; } - print '\n"; + print '\n"; if ($objp->fk_product > 0 && $objp->subprice <> $product->price) { @@ -297,6 +315,7 @@ if ($action == 'create') print "
'.$langs->trans("Description").''.$langs->trans("VAT").''.$langs->trans("Qty").'
'.$objp->tva_tx.' %'.$objp->qty.''.$objp->tva_tx.' %'.$objp->qty.''.$objp->remise_percent." % '.price($objp->subprice)."'.price($objp->subprice)."
"; print '
'; @@ -321,7 +340,7 @@ if ($action == 'create') } else { - print "Erreur facture $facture->id inexistante"; + print "Erreur facture $invoice->id inexistante"; } } else @@ -330,34 +349,31 @@ else * View mode */ - if ($facid > 0) + if ($id > 0) { - $fac = new FactureRec($db); - - if ($fac->fetch($facid, $user->societe_id) > 0) + if ($object->fetch($id) > 0) { - $soc = new Societe($db); - $soc->fetch($fac->socid); - $author = new User($db); - $author->fetch($fac->user_author); + $object->fetch_thirdparty(); + $author = new User($db); + $author->fetch($object->user_author); dol_fiche_head($head, 'compta', $langs->trans("PredefinedInvoices"),0,'company'); // Add a div print ''; print ''; - print ''; + print ''; print ''; - print ''; + print ''; print ""; print ""; - if ($fac->remise_percent > 0) + if ($object->remise_percent > 0) { print '"; print ''; - print ''; + print ''; print ''; - print ''; + print ''; print ''; - print ''; + print ''; print ''; - if ($fac->note) + if ($object->note) { - print '"; + print '"; } print "
'.$langs->trans("Ref").''.$fac->titre.''.$object->titre.'
'.$langs->trans("Customer").''.$soc->getNomUrl(1).''.$object->thirdparty->getNomUrl(1).'". $langs->trans("PaymentConditions") ." : "; - $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?facid='.$fac->id,$fac->cond_reglement_id,'none'); + $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id,'none'); print "
".$langs->trans("Author")."".$author->getFullName($langs)."'; } @@ -367,20 +383,20 @@ else } print $langs->trans("PaymentMode") ." : "; - $form->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$fac->id,$fac->mode_reglement_id,'none'); + $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id,'none'); print "
'.$langs->trans("AmountHT").''.price($fac->total_ht).''.price($object->total_ht).''.$langs->trans("Currency".$conf->currency).'
'.$langs->trans("AmountVAT").''.price($fac->total_tva).'
'.$langs->trans("AmountVAT").''.price($object->total_tva).''.$langs->trans("Currency".$conf->currency).'
'.$langs->trans("AmountTTC").''.price($fac->total_ttc).'
'.$langs->trans("AmountTTC").''.price($object->total_ttc).''.$langs->trans("Currency".$conf->currency).'
'.$langs->trans("Note").' : '.nl2br($fac->note)."
'.$langs->trans("Note").' : '.nl2br($object->note)."
"; @@ -390,11 +406,14 @@ else /* * Lines */ - if ($conf->service->enabled) { - print_titre($langs->trans("ProductsAndServices")); - } else { - print_titre($langs->trans("Products")); - } + + $title = $langs->trans("ProductsAndServices"); + if (empty($conf->service->enabled)) + $title = $langs->trans("Products"); + else if (empty($conf->product->enabled)) + $title = $langs->trans("Services"); + + print_titre($title); print ''; print ''; @@ -403,7 +422,7 @@ else print ''; print ''; - $num = count($fac->lines); + $num = count($object->lines); $i = 0; $var=True; while ($i < $num) @@ -413,7 +432,7 @@ else $product_static=new Product($db); // Show product and description - $type=$fac->lines[$i]->product_type?$fac->lines[$i]->product_type:$fac->lines[$i]->fk_product_type; + $type=(isset($object->lines[$i]->product_type)?$object->lines[$i]->product_type:$object->lines[$i]->fk_product_type); // Try to enhance type detection using date_start and date_end for free lines when type // was not saved. if (! empty($objp->date_start)) $type=1; @@ -421,26 +440,26 @@ else // Show line print ""; - if ($fac->lines[$i]->fk_product > 0) + if ($object->lines[$i]->fk_product > 0) { print ''; } @@ -450,16 +469,25 @@ else if ($type==1) $text = img_object($langs->trans('Service'),'service'); else $text = img_object($langs->trans('Product'),'product'); - print $text.' '.nl2br($fac->lines[$i]->desc); + + if (! empty($object->lines[$i]->label)) { + + $text.= ' '.$object->lines[$i]->label.''; + print $form->textwithtooltip($text,dol_htmlentitiesbr($object->lines[$i]->desc),3,'','',$i); + + } else { + + print $text.' '.nl2br($object->lines[$i]->desc); + } // Show range - print_date_range($fac->lines[$i]->date_start,$fac->lines[$i]->date_end); + print_date_range($object->lines[$i]->date_start, $object->lines[$i]->date_end); print ''; } - print ""; - print ''; - print "\n"; + print ''; + print ''; + print ''."\n"; $i++; } print '
'.$langs->trans("ReductionShort").''.$langs->trans("Qty").'
'; - print ''; // ancre pour retourner sur la ligne + print ''; // ancre pour retourner sur la ligne // Show product and description - $product_static->type=$fac->lines[$i]->fk_product_type; - $product_static->id=$fac->lines[$i]->fk_product; - $product_static->ref=$fac->lines[$i]->product_ref; - $product_static->libelle=$fac->lines[$i]->libelle; + $product_static->type=$object->lines[$i]->fk_product_type; + $product_static->id=$object->lines[$i]->fk_product; + $product_static->ref=$object->lines[$i]->product_ref; $text=$product_static->getNomUrl(1); - $text.= ' - '.$fac->lines[$i]->libelle; - $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($fac->lines[$i]->desc)); + $text.= ' - '.(! empty($object->lines[$i]->label)?$object->lines[$i]->label:$object->lines[$i]->product_label); + $description=(! empty($conf->global->PRODUIT_DESC_IN_FORM)?'':dol_htmlentitiesbr($object->lines[$i]->desc)); print $form->textwithtooltip($text,$description,3,'','',$i); // Show range - print_date_range($fac->lines[$i]->date_start,$fac->lines[$i]->date_end); + print_date_range($object->lines[$i]->date_start, $object->lines[$i]->date_end); // Add description in form - if ($conf->global->PRODUIT_DESC_IN_FORM) print ($fac->lines[$i]->desc && $fac->lines[$i]->desc!=$fac->lines[$i]->libelle)?'
'.dol_htmlentitiesbr($fac->lines[$i]->desc):''; + if (! empty($conf->global->PRODUIT_DESC_IN_FORM)) + print (! empty($object->lines[$i]->desc) && $object->lines[$i]->desc!=$fac->lines[$i]->product_label)?'
'.dol_htmlentitiesbr($object->lines[$i]->desc):''; print '
".price($fac->lines[$i]->price)."'.$fac->lines[$i]->remise_percent.' %".$fac->lines[$i]->qty."
'.price($object->lines[$i]->price).''.$object->lines[$i]->remise_percent.' %'.$object->lines[$i]->qty.'
'; @@ -471,9 +499,9 @@ else */ print '
'; - if ($fac->statut == 0 && $user->rights->facture->supprimer) + if ($object->statut == 0 && $user->rights->facture->supprimer) { - print ''.$langs->trans('Delete').''; + print ''.$langs->trans('Delete').''; } print '
'; @@ -489,20 +517,17 @@ else * List mode */ - if ($user->rights->facture->lire) - { + $sql = "SELECT s.nom, s.rowid as socid, f.titre, f.total, f.rowid as facid"; + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_rec as f"; + $sql.= " WHERE f.fk_soc = s.rowid"; + $sql.= " AND f.entity = ".$conf->entity; + if ($socid) $sql .= " AND s.rowid = ".$socid; + + //$sql .= " ORDER BY $sortfield $sortorder, rowid DESC "; + // $sql .= $db->plimit($limit + 1,$offset); + + $result = $db->query($sql); - $sql = "SELECT s.nom, s.rowid as socid, f.titre, f.total, f.rowid as facid"; - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_rec as f"; - $sql.= " WHERE f.fk_soc = s.rowid"; - $sql.= " AND f.entity = ".$conf->entity; - if ($socid) $sql .= " AND s.rowid = ".$socid; - - //$sql .= " ORDER BY $sortfield $sortorder, rowid DESC "; - // $sql .= $db->plimit($limit + 1,$offset); - - $result = $db->query($sql); - } if ($result) { $num = $db->num_rows($result); @@ -527,7 +552,7 @@ else print "
'.img_object($langs->trans("ShowBill"),"bill").' '.$objp->titre; + print ''.img_object($langs->trans("ShowBill"),"bill").' '.$objp->titre; print "'.$objp->nom.'
+ + + + + + % load_tva('tva_tx',$line->tva_tx,$seller,$buyer,0,$line->info_bits,$line->product_type); ?> info_bits & 2) != 2) { ?> - +   @@ -134,7 +136,9 @@ $(document).ready(function() { if ($(this).attr('checked')) { $('#product_label').removeAttr('disabled').focus(); } else { - $('#product_label').attr('disabled','disabled'); + $('#product_label') + .attr('disabled','disabled') + .val($('#origin_label_cache').val()); } }); @@ -161,7 +165,13 @@ $(document).ready(function() { } }); - $('#price_ht').onDelayedKeyup({ handler: function() { + $('#price_ht').focusin(function() { + $('#price_base_type').html('HT'); + }); + + $('#price_ht').onDelayedKeyup({ + handler: function() { + $('#price_base_type').html('HT'); $.post('/core/ajax/price.php', { 'action': 'get_ttc', 'pu_ht': $(this).val(), @@ -183,7 +193,12 @@ $(document).ready(function() { } }); - $('#price_ttc').onDelayedKeyup({ handler: function() { + $('#price_ttc').focusin(function() { + $('#price_base_type').html('TTC'); + }); + + $('#price_ttc').onDelayedKeyup({ + handler: function() { $.post('/core/ajax/price.php', { 'action': 'get_ht', 'pu_ttc': $(this).val(), @@ -206,16 +221,29 @@ $(document).ready(function() { }); $('#tva_tx').change(function() { - $.post('/core/ajax/price.php', { - 'action': 'get_ttc', - 'pu_ht': $('#price_ht').val(), - 'tva_tx': $(this).val() - }, - function(data) { - if (data && data.price.length > 0) { - $('#price_ttc').val(data.price); - } - }, 'json'); + if ($('#price_base_type').html() == 'HT') { + $.post('/core/ajax/price.php', { + 'action': 'get_ttc', + 'pu_ht': $('#price_ht').val(), + 'tva_tx': $(this).val() + }, + function(data) { + if (data && data.price.length > 0) { + $('#price_ttc').val(data.price); + } + }, 'json'); + } else { + $.post('/core/ajax/price.php', { + 'action': 'get_ht', + 'pu_ttc': $('#price_ttc').val(), + 'tva_tx': $(this).val() + }, + function(data) { + if (data && data.price.length > 0) { + $('#price_ht').val(data.price); + } + }, 'json'); + } }); margin->enabled)) { ?> diff --git a/htdocs/core/tpl/objectline_view.tpl.php b/htdocs/core/tpl/objectline_view.tpl.php index 6d50b776c7f..015b51e8257 100644 --- a/htdocs/core/tpl/objectline_view.tpl.php +++ b/htdocs/core/tpl/objectline_view.tpl.php @@ -68,7 +68,7 @@ print_date_range($line->date_start, $line->date_end); // Add description in form - if ($conf->global->PRODUIT_DESC_IN_FORM) + if (! empty($conf->global->PRODUIT_DESC_IN_FORM)) { print (! empty($line->description) && $line->description!=$line->product_label)?'
'.dol_htmlentitiesbr($line->description):''; } diff --git a/htdocs/core/tpl/originproductline.tpl.php b/htdocs/core/tpl/originproductline.tpl.php index 1715f5a9116..4d8f2dac942 100644 --- a/htdocs/core/tpl/originproductline.tpl.php +++ b/htdocs/core/tpl/originproductline.tpl.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2010-2012 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php index 18de50e8c2c..05c0b56dc8b 100644 --- a/htdocs/fourn/commande/fiche.php +++ b/htdocs/fourn/commande/fiche.php @@ -36,8 +36,10 @@ require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; -if ($conf->produit->enabled) require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; -if ($conf->projet->enabled) require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; +if (! empty($conf->produit->enabled)) + require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; +if (! empty($conf->projet->enabled)) + require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; $langs->load('orders'); $langs->load('sendings'); @@ -404,7 +406,7 @@ else if ($action == 'confirm_deleteproductline' && $confirm == 'yes' && $user->r if (! $error) { - Header("Location: fiche.php?id=".$id); + Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); exit; } } @@ -465,7 +467,7 @@ else if ($action == 'confirm_approve' && $confirm == 'yes' && $user->rights->fou $result = $object->approve($user, $idwarehouse); if ($result > 0) { - Header("Location: fiche.php?id=".$id); + Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); exit; } else @@ -481,7 +483,7 @@ else if ($action == 'confirm_refuse' && $confirm == 'yes' && $user->rights->four $result = $object->refuse($user); if ($result > 0) { - Header("Location: fiche.php?id=".$id); + Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); exit; } else @@ -496,7 +498,7 @@ else if ($action == 'confirm_commande' && $confirm == 'yes' && $user->rights->fo $result = $object->commande($user, $_REQUEST["datecommande"], $_REQUEST["methode"], $_REQUEST['comment']); if ($result > 0) { - Header("Location: fiche.php?id=".$id); + Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); exit; } else @@ -534,7 +536,7 @@ else if ($action == 'livraison' && $user->rights->fournisseur->commande->recepti $result = $object->Livraison($user, $date_liv, $_POST["type"], $_POST["comment"]); if ($result > 0) { - Header("Location: fiche.php?id=".$id); + Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); exit; } else if($result == -3) @@ -559,7 +561,7 @@ else if ($action == 'confirm_cancel' && $confirm == 'yes' && $user->rights->four $result = $object->cancel($user); if ($result > 0) { - Header("Location: fiche.php?id=".$id); + Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); exit; } else @@ -1550,7 +1552,7 @@ if ($id > 0 || ! empty($ref)) $ajaxoptions=array( 'update' => array('pqty' => 'qty'), - 'disabled' => 'addPredefinedProductButton', + 'option_disabled' => 'addPredefinedProductButton', 'error' => $langs->trans("NoPriceDefinedForThisSupplier") ); $form->select_produits_fournisseurs($object->fourn_id, '', 'idprodfournprice', '', '', $ajaxoptions); diff --git a/htdocs/install/mysql/migration/3.2.0-3.3.0.sql b/htdocs/install/mysql/migration/3.2.0-3.3.0.sql index 4961a5c609b..8cd01a13aff 100755 --- a/htdocs/install/mysql/migration/3.2.0-3.3.0.sql +++ b/htdocs/install/mysql/migration/3.2.0-3.3.0.sql @@ -79,3 +79,4 @@ ALTER TABLE llx_commande_fournisseur ADD COLUMN date_livraison date NULL; ALTER TABLE llx_propaldet ADD COLUMN label varchar(255) DEFAULT NULL AFTER fk_product; ALTER TABLE llx_commandedet ADD COLUMN label varchar(255) DEFAULT NULL AFTER fk_product; ALTER TABLE llx_facturedet ADD COLUMN label varchar(255) DEFAULT NULL AFTER fk_product; +ALTER TABLE llx_facturedet_rec ADD COLUMN label varchar(255) DEFAULT NULL AFTER product_type; diff --git a/htdocs/install/mysql/tables/llx_facturedet_rec.sql b/htdocs/install/mysql/tables/llx_facturedet_rec.sql index 84309645dbd..fe40c1fe97e 100644 --- a/htdocs/install/mysql/tables/llx_facturedet_rec.sql +++ b/htdocs/install/mysql/tables/llx_facturedet_rec.sql @@ -1,8 +1,8 @@ -- =================================================================== --- Copyright (C) 2003 Rodolphe Quiedeville --- Copyright (C) 2009 Laurent Destailleur --- Copyright (C) 2010 Juanjo Menent --- Copyright (C) 2010 Regis Houssin +-- Copyright (C) 2003 Rodolphe Quiedeville +-- Copyright (C) 2009 Laurent Destailleur +-- Copyright (C) 2010 Juanjo Menent +-- Copyright (C) 2010-2012 Regis Houssin -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by @@ -21,25 +21,27 @@ create table llx_facturedet_rec ( - rowid integer AUTO_INCREMENT PRIMARY KEY, - fk_facture integer NOT NULL, - fk_parent_line integer NULL, - fk_product integer NULL, - product_type integer DEFAULT 0, - description text, - tva_tx double(6,3) DEFAULT 19.6, -- taux tva - localtax1_tx double(6,3) DEFAULT 0, -- tax local tax 1 - localtax2_tx double(6,3) DEFAULT 0, -- tax local tax 2 - qty real, -- quantity - remise_percent real DEFAULT 0, -- pourcentage de remise - remise real DEFAULT 0, -- montant de la remise - subprice double(24,8), -- prix avant remise - price double(24,8), -- prix final - total_ht double(24,8), -- Total HT de la ligne toute quantity et incluant remise ligne et globale - total_tva double(24,8), -- Total TVA de la ligne toute quantity et incluant remise ligne et globale - total_localtax1 double(24,8) DEFAULT 0, -- Total LocalTax1 for total quantity of line - total_localtax2 double(24,8) DEFAULT 0, -- total LocalTax2 for total quantity of line - total_ttc double(24,8), -- Total TTC de la ligne toute quantity et incluant remise ligne et globale - special_code integer UNSIGNED DEFAULT 0, -- code pour les lignes speciales - rang integer DEFAULT 0 -- ordre d'affichage + rowid integer AUTO_INCREMENT PRIMARY KEY, + fk_facture integer NOT NULL, + fk_parent_line integer NULL, + fk_product integer NULL, + product_type integer DEFAULT 0, + label varchar(255) DEFAULT NULL, + description text, + tva_tx double(6,3) DEFAULT 19.6, -- taux tva + localtax1_tx double(6,3) DEFAULT 0, -- tax local tax 1 + localtax2_tx double(6,3) DEFAULT 0, -- tax local tax 2 + qty real, -- quantity + remise_percent real DEFAULT 0, -- pourcentage de remise + remise real DEFAULT 0, -- montant de la remise + subprice double(24,8), -- prix avant remise + price double(24,8), -- prix final + total_ht double(24,8), -- Total HT de la ligne toute quantity et incluant remise ligne et globale + total_tva double(24,8), -- Total TVA de la ligne toute quantity et incluant remise ligne et globale + total_localtax1 double(24,8) DEFAULT 0, -- Total LocalTax1 for total quantity of line + total_localtax2 double(24,8) DEFAULT 0, -- total LocalTax2 for total quantity of line + total_ttc double(24,8), -- Total TTC de la ligne toute quantity et incluant remise ligne et globale + special_code integer UNSIGNED DEFAULT 0, -- code pour les lignes speciales + rang integer DEFAULT 0 -- ordre d'affichage + )ENGINE=innodb;