[ task #640 ] Better deposit invoice management

This commit is contained in:
fhenry 2013-04-20 17:10:03 +02:00
parent 61b78666a2
commit cae761d522
4 changed files with 1983 additions and 1898 deletions

View File

@ -794,6 +794,8 @@ else if ($action == 'add' && $user->rights->facture->creer)
} }
} }
// Standard or deposit or proforma invoice // Standard or deposit or proforma invoice
if (($_POST['type'] == 0 || $_POST['type'] == 3 || $_POST['type'] == 4) && $_POST['fac_rec'] <= 0) if (($_POST['type'] == 0 || $_POST['type'] == 3 || $_POST['type'] == 4) && $_POST['fac_rec'] <= 0)
{ {
@ -872,6 +874,76 @@ else if ($action == 'add' && $user->rights->facture->creer)
if ($id > 0) if ($id > 0)
{ {
//If deposit invoice
if ($_POST['type'] == 3) {
$typeamount=GETPOST('typedeposit','alpha');
$valuedeposit=GETPOST('valuedeposit','int');
if ($typeamount=='amount') {
$amountdeposit=$valuedeposit;
}else {
$amountdeposit=0;
dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
$classname = ucfirst($subelement);
$srcobject = new $classname($db);
dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add deposit line");
$result=$srcobject->fetch($object->origin_id);
if ($result > 0)
{
$totalamount=0;
$lines = $srcobject->lines;
$num=count($lines);
for ($i=0;$i<$num;$i++)
{
$totalamount=+$lines[$i]->subprice;
}
if ($totalamount!=0) {
$amountdeposit=($totalamount*$valuedeposit)/100;
}
}
else
{
$mesgs[]=$srcobject->error;
$error++;
}
}
$result = $object->addline(
$id,
$langs->trans('Deposit'),
$amountdeposit, //subprice
1, //quantity
$lines[$i]->tva_tx,
0, //localtax1_tx
0, //localtax2_tx
0, //fk_product
0, //remise_percent
0, //date_start
0, //date_end
0,
$lines[$i]->info_bits, //info_bits
0, //info_bits
'HT',
0,
0, //product_type
1,
$lines[$i]->special_code,
$object->origin,
0,
0,
0,
0,
$langs->trans('Deposit')
);
}else {
dol_include_once('/'.$element.'/class/'.$subelement.'.class.php'); dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
$classname = ucfirst($subelement); $classname = ucfirst($subelement);
@ -994,6 +1066,7 @@ else if ($action == 'add' && $user->rights->facture->creer)
$error++; $error++;
} }
} }
}
else else
{ {
$mesgs[]=$object->error; $mesgs[]=$object->error;
@ -1667,13 +1740,13 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
} }
$action = 'presend'; $action = 'presend';
} }
/* /*
* Generate document * Generate document
*/ */
else if ($action == 'builddoc') // En get ou en post else if ($action == 'builddoc') // En get ou en post
{ {
$object->fetch($id); $object->fetch($id);
$object->fetch_thirdparty(); $object->fetch_thirdparty();
@ -1701,11 +1774,11 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc')); header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
exit; exit;
} }
} }
// Remove file in doc form // Remove file in doc form
else if ($action == 'remove_file') else if ($action == 'remove_file')
{ {
if ($object->fetch($id)) if ($object->fetch($id))
{ {
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
@ -1720,10 +1793,10 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors'); else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
$action=''; $action='';
} }
} }
if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->facture->creer) if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->facture->creer)
{ {
if ($action == 'addcontact') if ($action == 'addcontact')
{ {
$result = $object->fetch($id); $result = $object->fetch($id);
@ -1781,10 +1854,10 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
dol_print_error($db); dol_print_error($db);
} }
} }
} }
if ($action == 'update_extras') if ($action == 'update_extras')
{ {
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$extralabels=$extrafields->fetch_name_optionals_label('facture'); $extralabels=$extrafields->fetch_name_optionals_label('facture');
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
@ -1807,30 +1880,30 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
} }
else if ($reshook < 0) $error++; else if ($reshook < 0) $error++;
} }
/* /*
* View * View
*/ */
$form = new Form($db); $form = new Form($db);
$formother=new FormOther($db); $formother=new FormOther($db);
$formfile = new FormFile($db); $formfile = new FormFile($db);
$bankaccountstatic=new Account($db); $bankaccountstatic=new Account($db);
$now=dol_now(); $now=dol_now();
llxHeader('',$langs->trans('Bill'),'EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes'); llxHeader('',$langs->trans('Bill'),'EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes');
/********************************************************************* /*********************************************************************
* *
* Mode creation * Mode creation
* *
**********************************************************************/ **********************************************************************/
if ($action == 'create') if ($action == 'create')
{ {
$facturestatic=new Facture($db); $facturestatic=new Facture($db);
$extralabels=$extrafields->fetch_name_optionals_label('facture'); $extralabels=$extrafields->fetch_name_optionals_label('facture');
@ -2039,14 +2112,20 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
print '</td></tr>'."\n"; print '</td></tr>'."\n";
} }
if (empty($origin)) if ((empty($origin)) || (($origin=='propal') && (!empty($originid))))
{ {
// Deposit // Deposit
print '<tr height="18"><td width="16px" valign="middle">'; print '<tr height="18"><td width="16px" valign="middle">';
print '<input type="radio" name="type" value="3"'.(GETPOST('type')==3?' checked="checked"':'').'>'; print '<input type="radio" name="type" value="3"'.(GETPOST('type')==3?' checked="checked"':'').'>';
print '</td><td valign="middle">'; print '</td><td valign="middle" nowrap="nowrap">';
$desc=$form->textwithpicto($langs->trans("InvoiceDeposit"),$langs->transnoentities("InvoiceDepositDesc"),1); $desc=$form->textwithpicto($langs->trans("InvoiceDeposit"),$langs->transnoentities("InvoiceDepositDesc"),1);
print $desc; print '<table class="nobordernopadding"><tr><td>'.$desc.'</td>';
if (($origin=='propal') ) {
print '<td><select name="typedeposit"><option value="amount">'.$langs->trans('FixAmount').'</option>';
print '<option value="variable">'.$langs->trans('VarAmount').'</option></select></td>';
print '<td>'.$langs->trans('Value').':<input type="text" name="valuedeposit" size="3" value="'.GETPOST('valuedeposit','int').'"/>';
}
print '</td></tr></table>';
print '</td></tr>'."\n"; print '</td></tr>'."\n";
} }
@ -2310,9 +2389,9 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
print '</table>'; print '</table>';
} }
} }
else if ($id > 0 || ! empty($ref)) else if ($id > 0 || ! empty($ref))
{ {
/* /*
* Show object in view mode * Show object in view mode
*/ */
@ -3703,10 +3782,10 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
{ {
dol_print_error($db,$object->error); dol_print_error($db,$object->error);
} }
} }
dol_htmloutput_mesg('',$mesgs); dol_htmloutput_mesg('',$mesgs);
llxFooter(); llxFooter();
$db->close(); $db->close();
?> ?>

View File

@ -311,6 +311,8 @@ PaymentConditionShortPT_ORDER=On order
PaymentConditionPT_ORDER=On order PaymentConditionPT_ORDER=On order
PaymentConditionShortPT_5050=50-50 PaymentConditionShortPT_5050=50-50
PaymentConditionPT_5050=50%% in advance, 50%% on delivery PaymentConditionPT_5050=50%% in advance, 50%% on delivery
FixAmount=Fix amount
VarAmount=Variable amount (%% tot.)
# PaymentType # PaymentType
PaymentTypeVIR=Bank deposit PaymentTypeVIR=Bank deposit

View File

@ -287,6 +287,8 @@ TotalOfTwoDiscountMustEqualsOriginal=La suma del importe de los 2 nuevos descuen
ConfirmRemoveDiscount=¿Está seguro de querer eliminar este descuento? ConfirmRemoveDiscount=¿Está seguro de querer eliminar este descuento?
RelatedBill=Factura asociada RelatedBill=Factura asociada
RelatedBills=Facturas asociadas RelatedBills=Facturas asociadas
FixAmount=Importe fijo
VarAmount=Importe variable (%% total)
# PaymentConditions # PaymentConditions
PaymentConditionShortRECEP=A la recepción PaymentConditionShortRECEP=A la recepción

View File

@ -322,6 +322,8 @@ PaymentTypeVAD=Paiement en ligne
PaymentTypeShortVAD=Paiement en ligne PaymentTypeShortVAD=Paiement en ligne
PaymentTypeTRA=Paiement par traite PaymentTypeTRA=Paiement par traite
PaymentTypeShortTRA=Traite PaymentTypeShortTRA=Traite
FixAmount=Montant Fixe
VarAmount=Montant variable (%% tot.)
BankDetails=Coordonnées bancaires BankDetails=Coordonnées bancaires
BankCode=Code banque BankCode=Code banque