Add feature : import line from origin invoice in the new credit note

This commit is contained in:
Alexis Algoud 2014-03-15 12:01:13 +01:00
parent 1d268c2e86
commit 3a21d99edf
2 changed files with 37 additions and 4 deletions

View File

@ -643,8 +643,37 @@ else if ($action == 'add' && $user->rights->facture->creer) {
$id = $object->create($user);
if(GETPOST('invoiceAvoirWithLines', 'int')==1 && $id>0) {
$facture_source = new Facture($db); // fetch origin object
if($facture_source->fetch($object->fk_facture_source)>0) {
foreach($facture_source->lines as $line) {
$line->fk_facture = $object->id;
$line->subprice =-$line->subprice; // invert price for object
$line->pa_ht = -$line->pa_ht;
$line->total_ht=-$line->total_ht;
$line->total_tva=-$line->total_tva;
$line->total_ttc=-$line->total_ttc;
$line->total_localtax1=-$line->total_localtax1;
$line->total_localtax2=-$line->total_localtax2;
$line->insert();
$object->lines[] = $line; // insert new line in current object
}
$object->update_price(1);
}
}
// Add predefined lines
for($i = 1; $i <= $NBLINES; $i ++) {
/*
TODO delete
for($i = 1; $i <= $NBLINES; $i ++) {
if ($_POST ['idprod' . $i]) {
$product = new Product($db);
$product->fetch($_POST ['idprod' . $i]);
@ -652,7 +681,7 @@ else if ($action == 'add' && $user->rights->facture->creer) {
$endday = dol_mktime(12, 0, 0, $_POST ['date_end' . $i . 'month'], $_POST ['date_end' . $i . 'day'], $_POST ['date_end' . $i . 'year']);
$result = $object->addline($product->description, $product->price, $_POST ['qty' . $i], $product->tva_tx, $product->localtax1_tx, $product->localtax2_tx, $_POST ['idprod' . $i], $_POST ['remise_percent' . $i], $startday, $endday, 0, 0, '', $product->price_base_type, $product->price_ttc, $product->type);
}
}
}*/
}
}
@ -2000,12 +2029,12 @@ if ($action == 'create')
if (empty($origin) && $socid > 0)
{
// Credit note
print '<tr height="18"><td valign="middle">';
print '<tr height="18"><td valign="top">';
print '<input type="radio" id="radio_creditnote" name="type" value="2"' . (GETPOST('type') == 2 ? ' checked=true' : '');
if (! $optionsav)
print ' disabled="disabled"';
print '>';
print '</td><td valign="middle">';
print '</td><td valign="top">';
print '<script type="text/javascript" language="javascript">
jQuery(document).ready(function() {
jQuery("#fac_avoir").click(function() {
@ -2028,6 +2057,9 @@ if ($action == 'create')
$text .= '</select>';
$desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceAvoirDesc"), 1);
print $desc;
print '&nbsp;&nbsp;&nbsp; <input type="checkbox" name="invoiceAvoirWithLines" id="invoiceAvoirWithLines" value="1" onclick="if($(this).is(\':checked\') ) { $(\'#radio_creditnote\').attr(\'checked\',\'checked\') }" /> <label for="invoiceAvoirWithLines">'.$langs->trans('invoiceAvoirWithLines')."</label>";
print '</td></tr>' . "\n";
}

View File

@ -28,6 +28,7 @@ InvoiceReplacementDesc=La <b>facture de remplacement</b> sert à annuler et remp
InvoiceAvoir=Facture avoir
InvoiceAvoirAsk=Facture avoir pour correction de la facture
InvoiceAvoirDesc=La <b>facture d'avoir</b> est une facture négative destinée à compenser un montant de facture qui diffère du montant réellement versé (suite à un trop versé par le client par erreur ou un manque non versé par le client suite à un retour produit par exemple).
invoiceAvoirWithLines=Créer la facture d'avoir avec les lignes de la facture d'origine
ReplaceInvoice=Remplace la facture %s
ReplacementInvoice=Remplacement facture
ReplacedByInvoice=Remplacée par la facture %s