New: [ task #498 ] part 3

This commit is contained in:
Regis Houssin 2012-08-25 03:28:30 +02:00
parent a0b3ea0dd4
commit c9113458d9
17 changed files with 623 additions and 459 deletions

View File

@ -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 '</td>';
if ($action != 'refclient' && ! empty($object->brouillon)) print '<td align="right"><a href="'.$_SERVER['PHP_SELF'].'?action=refclient&amp;id='.$object->id.'">'.img_edit($langs->trans('Modify')).'</a></td>';
print '</tr></table>';
print '</td><td colspan="5">';
if ($user->rights->propale->creer && $action == 'refclient')
if ($user->rights->propal->creer && $action == 'refclient')
{
print '<form action="propal.php?id='.$object->id.'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
@ -1454,7 +1501,7 @@ if (! empty($conf->projet->enabled))
print '<tr><td>';
print '<table class="nobordernopadding" width="100%"><tr><td>';
print $langs->trans('Project').'</td>';
if ($user->rights->propale->creer)
if ($user->rights->propal->creer)
{
if ($action != 'classify') print '<td align="right"><a href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a></td>';
print '</tr></table>';
@ -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 '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=validate">'.$langs->trans('Validate').'</a>';
else print '<a class="butActionRefused" href="#">'.$langs->trans('Validate').'</a>';
}
// Edit
if ($object->statut == 1 && $user->rights->propale->creer)
if ($object->statut == 1 && $user->rights->propal->creer)
{
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=modif">'.$langs->trans('Modify').'</a>';
}
// ReOpen
if (($object->statut == 2 || $object->statut == 3) && $user->rights->propale->cloturer)
if (($object->statut == 2 || $object->statut == 3) && $user->rights->propal->cloturer)
{
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=reopen'.(empty($conf->global->MAIN_JUMP_TAG)?'':'#reopen').'"';
print '>'.$langs->trans('ReOpen').'</a>';
@ -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 '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=presend&amp;mode=init">'.$langs->trans('SendByMail').'</a>';
}
@ -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 '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=statut'.(empty($conf->global->MAIN_JUMP_TAG)?'':'#close').'"';
print '>'.$langs->trans('Close').'</a>';
}
// Clone
if ($user->rights->propale->creer)
if ($user->rights->propal->creer)
{
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;socid='.$object->socid.'&amp;action=clone&amp;object='.$object->element.'">'.$langs->trans("ToClone").'</a>';
}
// Delete
if ($user->rights->propale->supprimer)
if ($user->rights->propal->supprimer)
{
print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete"';
print '>'.$langs->trans('Delete').'</a>';
@ -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;

View File

@ -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;

View File

@ -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 '<input type="hidden" name="action" value="add">';
print '<input type="hidden" name="socid" value="'.$soc->id.'">' ."\n";
print '<input type="hidden" name="remise_percent" value="'.$soc->remise_client.'">';
print '<input name="facnumber" type="hidden" value="provisoire">';
print '<input type="hidden" name="origin" value="'.$origin.'">';
print '<input type="hidden" name="originid" value="'.$originid.'">';
@ -1553,7 +1557,7 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G
print '</td></tr>';
}
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 '<tr><td>';
// 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);

View File

@ -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[] = '<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")).'</div>';
$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[] = '<div class="error">'.$langs->trans("CantBeLessThanMinPrice",price2num($price_min,'MU').' '.$langs->trans("Currency".$conf->currency)).'</div>';
$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 '<input name="facnumber" type="hidden" value="provisoire">';
print '<input name="ref_client" type="hidden" value="'.$ref_client.'">';
print '<input name="ref_int" type="hidden" value="'.$ref_int.'">';
print '<input type="hidden" name="origin" value="'.GETPOST('origin').'">';
print '<input type="hidden" name="originid" value="'.GETPOST('originid').'">';
print '<input type="hidden" name="origin" value="'.$origin.'">';
print '<input type="hidden" name="originid" value="'.$originid.'">';
print '<table class="border" width="100%">';
@ -1766,7 +1788,7 @@ if ($action == 'create')
print '<tr><td class="fieldrequired">'.$langs->trans('Ref').'</td><td colspan="2">'.$langs->trans('Draft').'</td></tr>';
// 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 '<option value="'.$objp->rowid.'"';
if ($_POST["fac_rec"] == $objp->rowid) print ' selected="selected"';
if (GETPOST('fac_rec') == $objp->rowid) print ' selected="selected"';
print '>'.$objp->titre.' ('.price($objp->total_ttc).' '.$langs->trans("TTC").')</option>';
$i++;
}
@ -1997,23 +2019,23 @@ if ($action == 'create')
print '</textarea></td></tr>';
// Private note
if (! $user->societe_id)
if (empty($user->societe_id))
{
print '<tr>';
print '<td class="border" valign="top">'.$langs->trans('NotePrivate').'</td>';
print '<td valign="top" colspan="2">';
print '<textarea name="note" wrap="soft" cols="70" rows="'.ROWS_3.'">';
if (is_object($objectsrc)) // Take value from source object
if (! empty($origin) && ! empty($originid) && is_object($objectsrc)) // Take value from source object
{
print $objectsrc->note;
}
print '</textarea></td></tr>';
}
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 '<tr><td colspan="3">';
@ -2113,7 +2135,7 @@ if ($action == 'create')
print "</form>\n";
// Show origin lines
if (is_object($objectsrc))
if (! empty($origin) && ! empty($originid) && is_object($objectsrc))
{
print '<br>';

View File

@ -1,8 +1,8 @@
<?php
/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2009 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2009-2012 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
*
* 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)."'";

View File

@ -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)

View File

@ -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 = '<div class="error">'.$facturerec->error.'</div>';
$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.'<br>';
$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 '<form action="fiche-rec.php" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="add">';
print '<input type="hidden" name="facid" value="'.$facture->id.'">';
print '<input type="hidden" name="facid" value="'.$invoice->id.'">';
print '<table class="border" width="100%">';
$facture->fetch_thirdparty();
$invoice->fetch_thirdparty();
print '<tr><td>'.$langs->trans("Customer").'</td><td>'.$facture->client->getNomUrl(1).'</td>';
print '<tr><td>'.$langs->trans("Customer").'</td><td>'.$invoice->client->getNomUrl(1).'</td>';
print '<td>';
//print $langs->trans("NotePrivate");
print '</td></tr>';
@ -134,20 +142,20 @@ if ($action == 'create')
print "<tr><td>".$langs->trans("Author")."</td><td>".$user->getFullName($langs)."</td></tr>";
print "<tr><td>".$langs->trans("PaymentConditions")."</td><td>";
$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 "</td></tr>";
print "<tr><td>".$langs->trans("PaymentMode")."</td><td>";
$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 "</td></tr>";
if ($conf->projet->enabled)
if (! empty($conf->projet->enabled))
{
print "<tr><td>".$langs->trans("Project")."</td><td>";
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 "</td></tr>";
@ -155,14 +163,15 @@ if ($action == 'create')
print "</table>";
print '<br>';
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 '<table class="notopnoleftnoright" width="100%">';
print '<tr><td colspan="3">';
$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 '<table class="notopnoleftnoright" width="100%">';
if ($num)
{
print "<tr class=\"liste_titre\">";
print '<tr class="liste_titre">';
print '<td width="54%">'.$langs->trans("Description").'</td>';
print '<td width="8%" align="center">'.$langs->trans("VAT").'</td>';
print '<td width="8%" align="center">'.$langs->trans("Qty").'</td>';
@ -217,7 +226,7 @@ if ($action == 'create')
print "<tr $bc[$var]>";
// 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)?'<br>'.dol_htmlentitiesbr($objp->description):'';
if (! empty($conf->global->PRODUIT_DESC_IN_FORM))
print (! empty($objp->description) && $objp->description!=$objp->product_label)?'<br>'.dol_htmlentitiesbr($objp->description):'';
print '</td>';
}
@ -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.= ' <strong>'.$objp->custom_label.'</strong>';
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 "</td>\n";
}
print '<TD align="center">'.$objp->tva_tx.' %</TD>';
print '<TD align="center">'.$objp->qty.'</TD>';
print '<td align="center">'.$objp->tva_tx.' %</td>';
print '<td align="center">'.$objp->qty.'</td>';
if ($objp->remise_percent > 0)
{
print '<td align="right">'.$objp->remise_percent." %</td>\n";
@ -270,7 +288,7 @@ if ($action == 'create')
print '<td>&nbsp;</td>';
}
print '<TD align="right">'.price($objp->subprice)."</td>\n";
print '<td align="right">'.price($objp->subprice)."</td>\n";
if ($objp->fk_product > 0 && $objp->subprice <> $product->price)
{
@ -297,6 +315,7 @@ if ($action == 'create')
print "</table>";
print '</td></tr>';
// TODO not used
if ($flag_different_price)
{
print '<tr><td colspan="3" align="left">';
@ -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 '<table class="border" width="100%">';
print '<tr><td>'.$langs->trans("Ref").'</td>';
print '<td colspan="4">'.$fac->titre.'</td>';
print '<td colspan="4">'.$object->titre.'</td>';
print '<tr><td>'.$langs->trans("Customer").'</td>';
print '<td colspan="3">'.$soc->getNomUrl(1).'</td>';
print '<td colspan="3">'.$object->thirdparty->getNomUrl(1).'</td>';
print "<td>". $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 "</td></tr>";
print "<tr><td>".$langs->trans("Author")."</td><td colspan=\"3\">".$author->getFullName($langs)."</td>";
if ($fac->remise_percent > 0)
if ($object->remise_percent > 0)
{
print '<td rowspan="5" valign="top">';
}
@ -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 "</td></tr>";
print '<tr><td>'.$langs->trans("AmountHT").'</td>';
print '<td align="right" colspan="2"><b>'.price($fac->total_ht).'</b></td>';
print '<td align="right" colspan="2"><b>'.price($object->total_ht).'</b></td>';
print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
print '<tr><td>'.$langs->trans("AmountVAT").'</td><td align="right" colspan="2">'.price($fac->total_tva).'</td>';
print '<tr><td>'.$langs->trans("AmountVAT").'</td><td align="right" colspan="2">'.price($object->total_tva).'</td>';
print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
print '<tr><td>'.$langs->trans("AmountTTC").'</td><td align="right" colspan="2">'.price($fac->total_ttc).'</td>';
print '<tr><td>'.$langs->trans("AmountTTC").'</td><td align="right" colspan="2">'.price($object->total_ttc).'</td>';
print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
if ($fac->note)
if ($object->note)
{
print '<tr><td colspan="5">'.$langs->trans("Note").' : '.nl2br($fac->note)."</td></tr>";
print '<tr><td colspan="5">'.$langs->trans("Note").' : '.nl2br($object->note)."</td></tr>";
}
print "</table>";
@ -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 '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
@ -403,7 +422,7 @@ else
print '<td align="center">'.$langs->trans("ReductionShort").'</td>';
print '<td align="center">'.$langs->trans("Qty").'</td></tr>';
$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 "<tr $bc[$var]>";
if ($fac->lines[$i]->fk_product > 0)
if ($object->lines[$i]->fk_product > 0)
{
print '<td>';
print '<a name="'.$fac->lines[$i]->id.'"></a>'; // ancre pour retourner sur la ligne
print '<a name="'.$object->lines[$i]->id.'"></a>'; // 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)?'<br>'.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)?'<br>'.dol_htmlentitiesbr($object->lines[$i]->desc):'';
print '</td>';
}
@ -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.= ' <strong>'.$object->lines[$i]->label.'</strong>';
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 '</td>';
}
print "<td align=\"right\">".price($fac->lines[$i]->price)."</td>";
print '<td align="center">'.$fac->lines[$i]->remise_percent.' %</td>';
print "<td align=\"center\">".$fac->lines[$i]->qty."</td></tr>\n";
print '<td align="right">'.price($object->lines[$i]->price).'</td>';
print '<td align="center">'.$object->lines[$i]->remise_percent.' %</td>';
print '<td align="center">'.$object->lines[$i]->qty.'</td></tr>'."\n";
$i++;
}
print '</table>';
@ -471,9 +499,9 @@ else
*/
print '<div class="tabsAction">';
if ($fac->statut == 0 && $user->rights->facture->supprimer)
if ($object->statut == 0 && $user->rights->facture->supprimer)
{
print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=delete&facid='.$fac->id.'">'.$langs->trans('Delete').'</a>';
print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=delete&id='.$object->id.'">'.$langs->trans('Delete').'</a>';
}
print '</div>';
@ -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 "<tr $bc[$var]>";
print '<td><a href="'.$_SERVER['PHP_SELF'].'?facid='.$objp->facid.'">'.img_object($langs->trans("ShowBill"),"bill").' '.$objp->titre;
print '<td><a href="'.$_SERVER['PHP_SELF'].'?id='.$objp->facid.'">'.img_object($langs->trans("ShowBill"),"bill").' '.$objp->titre;
print "</a></td>\n";
print '<td><a href="../fiche.php?socid='.$objp->socid.'">'.$objp->nom.'</a></td>';

View File

@ -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');

View File

@ -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;
}
}

View File

@ -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 '</select>';
//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 '<input type="hidden" name="'.$htmlname.'" value="1">';
}
if (! $forceall && $conf->product->enabled && empty($conf->service->enabled))
if (! $forceall && ! empty($conf->product->enabled) && empty($conf->service->enabled))
{
print '<input type="hidden" name="'.$htmlname.'" value="0">';
}

View File

@ -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)) {
<span id="update_price_area" class="hideobject"> | <input type="checkbox" id="update_price_checkbox" name="update_price" value="1" />
<?php echo $form->textwithtooltip($langs->trans('UpdateOriginalProductPrice'), $langs->trans('HelpUpdateOriginalProductPrice'),1,0,'','',3); ?>
</span>
<span id="price_base_type" class="hideobject"></span>
</td>
</tr>
<?php } ?>
@ -121,7 +125,8 @@ if (! empty($conf->margin->enabled)) {
echo '<input id="product_ref" name="product_ref" size="20" value="'.GETPOST('product_ref').'"></span>';
echo '&nbsp;<label for="product_label">'.$langs->trans("Label").'</label>';
echo '<input id="product_label" name="product_label" size="40" value="'.GETPOST('product_label').'">';
echo '<input id="product_label" name="product_label" size="40" value="'.GETPOST('product_label').'">';
echo '<input type="hidden" id="origin_label_cache" name="origin_label_cache" value="" />';
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);
?>
</td>
<td align="right"><input type="text" size="6" id="price_ht" name="price_ht" value="<?php echo (GETPOST('price_ht')?GETPOST('price_ht'):''); ?>"></td>
<td align="right"><input type="text" size="6" id="price_ttc" name="price_ttc" value="<?php echo (GETPOST('price_ttc')?GETPOST('price_ttc'):''); ?>"></td>
<td align="right"><input type="text" size="2" id="qty" name="qty" value="<?php echo (GETPOST('qty')?GETPOST('qty'):1); ?>"></td>
<td align="right">
<input type="text" size="8" id="price_ht" name="price_ht" value="<?php echo (GETPOST('price_ht')?GETPOST('price_ht'):''); ?>">
<input type="hidden" id="origin_price_ht_cache" name="origin_price_ht_cache" value="" />
</td>
<td align="right">
<input type="text" size="8" id="price_ttc" name="price_ttc" value="<?php echo (GETPOST('price_ttc')?GETPOST('price_ttc'):''); ?>">
<input type="hidden" id="origin_price_ttc_cache" name="origin_price_ttc_cache" value="" />
</td>
<td align="right"><input type="text" size="3" id="qty" name="qty" value="<?php echo (GETPOST('qty')?GETPOST('qty'):1); ?>"></td>
<td align="right" nowrap="nowrap"><input type="text" size="1" value="<?php echo $buyer->remise_client; ?>" name="remise_percent">%</td>
<?php
$colspan = 4;
@ -217,6 +228,7 @@ $(document).ready(function() {
} else {
$('#update_desc_checkbox').removeAttr('checked').trigger('change');
$('#update_price_checkbox').removeAttr('checked').trigger('change');
}
});
@ -243,7 +255,7 @@ $(document).ready(function() {
}
} else {
//$('#add_product_area').hide(); // TODO for add product card
$('#add_product_checkbox').removeAttr('checked');
$('#add_product_checkbox').removeAttr('checked').trigger('change');
$('#addlinebutton').attr('disabled','disabled');
$('#service_duration_area').hide();
$('#date_start').val('').trigger('change');
@ -287,8 +299,14 @@ $(document).ready(function() {
$('#price_ht').removeAttr('disabled').focus();
$('#price_ttc').removeAttr('disabled')
} else {
$('#price_ht').attr('disabled','disabled');
$('#price_ttc').attr('disabled','disabled');
$('#price_ht')
.attr('disabled','disabled')
.val($('#origin_price_ht_cache').val())
.trigger('change');
$('#price_ttc')
.attr('disabled','disabled')
.val($('#origin_price_ttc_cache').val())
.trigger('change');
}
});
@ -305,7 +323,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());
$('#search_idprod').focus();
}
});
@ -343,7 +363,12 @@ $(document).ready(function() {
}
});
$('#price_ht').onDelayedKeyup({ handler: function() {
$('#price_ht').focusin(function() {
$('#price_base_type').html('HT');
});
$('#price_ht').onDelayedKeyup({
handler: function() {
$.post('<?php echo DOL_URL_ROOT; ?>/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('<?php echo DOL_URL_ROOT; ?>/core/ajax/price.php', {
'action': 'get_ht',
'pu_ttc': $(this).val(),
@ -388,16 +418,29 @@ $(document).ready(function() {
});
$('#tva_tx').change(function() {
$.post('<?php echo DOL_URL_ROOT; ?>/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('<?php echo DOL_URL_ROOT; ?>/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('<?php echo DOL_URL_ROOT; ?>/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');
}
});
});
</script>

View File

@ -46,9 +46,11 @@
<?php } ?>
<input id="product_label" name="product_label" size="40" value="<?php echo $label; ?>"<?php echo $placeholder . ((! empty($line->fk_product) && empty($line->label)) ? ' disabled="disabled"' : ''); ?>>
<input type="hidden" id="origin_label_cache" name="origin_label_cache" value="<?php echo $line->product_label; ?>" />
<span id="update_label_area" class="hideobject"><input type="checkbox" id="update_label_checkbox" name="update_label" value="1" />
<?php echo $form->textwithtooltip($langs->trans('UpdateOriginalProductLabel'), $langs->trans('HelpUpdateOriginalProductLabel'),1,0,'','',3); ?>
</span>
<span id="price_base_type" class="hideobject"></span>
<br>
@ -71,12 +73,12 @@
<td align="right"><?php echo $form->load_tva('tva_tx',$line->tva_tx,$seller,$buyer,0,$line->info_bits,$line->product_type); ?></td>
<td align="right"><input type="text" class="flat" size="6" id="price_ht" name="price_ht" value="<?php echo price($line->subprice,0,'',0); ?>"></td>
<td align="right"><input type="text" class="flat" size="6" id="price_ttc" name="price_ttc" value="<?php echo price($pu_ttc,0,'',0); ?>"></td>
<td align="right"><input type="text" class="flat" size="8" id="price_ht" name="price_ht" value="<?php echo price($line->subprice,0,'',0); ?>"></td>
<td align="right"><input type="text" class="flat" size="8" id="price_ttc" name="price_ttc" value="<?php echo price($pu_ttc,0,'',0); ?>"></td>
<td align="right">
<?php if (($line->info_bits & 2) != 2) { ?>
<input size="2" type="text" class="flat" name="qty" value="<?php echo $line->qty; ?>">
<input size="3" type="text" class="flat" name="qty" value="<?php echo $line->qty; ?>">
<?php } else { ?>
&nbsp;
<?php } ?>
@ -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('<?php echo DOL_URL_ROOT; ?>/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('<?php echo DOL_URL_ROOT; ?>/core/ajax/price.php', {
'action': 'get_ht',
'pu_ttc': $(this).val(),
@ -206,16 +221,29 @@ $(document).ready(function() {
});
$('#tva_tx').change(function() {
$.post('<?php echo DOL_URL_ROOT; ?>/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('<?php echo DOL_URL_ROOT; ?>/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('<?php echo DOL_URL_ROOT; ?>/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');
}
});
<?php if (! empty($conf->margin->enabled)) { ?>

View File

@ -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)?'<br>'.dol_htmlentitiesbr($line->description):'';
}

View File

@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2010-2011 Regis Houssin <regis@dolibarr.fr>
/* Copyright (C) 2010-2012 Regis Houssin <regis@dolibarr.fr>
*
* 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

View File

@ -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);

View File

@ -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;

View File

@ -1,8 +1,8 @@
-- ===================================================================
-- Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
-- Copyright (C) 2009 Laurent Destailleur <eldy@users.sourceforge.net>
-- Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
-- Copyright (C) 2010 Regis Houssin <regis@dolibarr.fr>
-- Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
-- Copyright (C) 2009 Laurent Destailleur <eldy@users.sourceforge.net>
-- Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
-- Copyright (C) 2010-2012 Regis Houssin <regis@dolibarr.fr>
--
-- 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;