Skip to content
Snippets Groups Projects
Commit 09355bcc authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop

parents fc65d5fb e17eea5e
No related branches found
No related tags found
No related merge requests found
......@@ -177,6 +177,11 @@ class FactureFournisseur extends CommonInvoice
*/
const STATUS_ABANDONED = 3;
const CLOSECODE_DISCOUNTVAT = 'discount_vat';
const CLOSECODE_BADCREDIT = 'badsupplier';
const CLOSECODE_ABANDONED = 'abandon';
const CLOSECODE_REPLACED = 'replaced';
/**
* Constructor
*
......
......@@ -8,6 +8,7 @@
* Copyright (C) 2013-2015 Philippe Grand <philippe.grand@atoo-net.com>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
*
* 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
......@@ -55,12 +56,15 @@ $langs->load('banks');
if (!empty($conf->incoterm->enabled)) $langs->load('incoterm');
$id = (GETPOST('facid','int') ? GETPOST('facid','int') : GETPOST('id','int'));
$socid = GETPOST('socid', 'int');
$action = GETPOST("action");
$confirm = GETPOST("confirm");
$ref = GETPOST('ref','alpha');
$cancel = GETPOST('cancel','alpha');
$lineid = GETPOST('lineid', 'int');
$projectid = GETPOST('projectid','int');
$origin = GETPOST('origin', 'alpha');
$originid = GETPOST('origin', 'int');
//PDF
$hidedetails = (GETPOST('hidedetails','int') ? GETPOST('hidedetails','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
......@@ -1161,14 +1165,14 @@ if ($action == 'create')
if (!empty($conf->multicurrency->enabled) && !empty($societe->multicurrency_code)) $currency_code = $societe->multicurrency_code;
}
if (GETPOST('origin') && GETPOST('originid'))
if (! empty($origin) && ! empty($originid))
{
// Parse element/subelement (ex: project_task)
$element = $subelement = GETPOST('origin');
$element = $subelement = $origin;
if ($element == 'project')
{
$projectid=GETPOST('originid');
$projectid = $originid;
$element = 'projet';
}
else if (in_array($element,array('order_supplier')))
......@@ -1191,7 +1195,7 @@ if ($action == 'create')
$classname = ucfirst($subelement);
if ($classname == 'Fournisseur.commande') $classname='CommandeFournisseur';
$objectsrc = new $classname($db);
$objectsrc->fetch(GETPOST('originid'));
$objectsrc->fetch($originid);
$objectsrc->fetch_thirdparty();
$projectid = (!empty($objectsrc->fk_project)?$objectsrc->fk_project:'');
......@@ -1230,12 +1234,12 @@ if ($action == 'create')
if (!empty($conf->multicurrency->enabled) && !empty($soc->multicurrency_code)) $currency_code = $soc->multicurrency_code;
}
print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="add">';
print '<input type="hidden" name="origin" value="'.GETPOST('origin').'">';
print '<input type="hidden" name="originid" value="'.GETPOST('originid').'">';
if ($societe->id > 0) print '<input type="hidden" name="socid" value="' . $societe->id . '">' . "\n";
print '<input type="hidden" name="origin" value="'.$origin.'">';
print '<input type="hidden" name="originid" value="'.$originid.'">';
if (!empty($currency_tx)) print '<input type="hidden" name="originmulticurrency_tx" value="' . $currency_tx . '">';
dol_fiche_head();
......@@ -1249,14 +1253,14 @@ if ($action == 'create')
print '<tr><td class="fieldrequired">'.$langs->trans('Supplier').'</td>';
print '<td>';
if (GETPOST('socid') > 0)
if ($societe->id > 0)
{
print $societe->getNomUrl(1);
print '<input type="hidden" name="socid" value="'.GETPOST('socid','int').'">';
print '<input type="hidden" name="socid" value="'.$societe->id.'">';
}
else
{
print $form->select_company(GETPOST('socid','int'), 'socid', 's.fournisseur = 1', 'SelectThirdParty');
print $form->select_company($societe->id, 'socid', 's.fournisseur = 1', 'SelectThirdParty');
}
print '</td></tr>';
......@@ -1264,84 +1268,223 @@ if ($action == 'create')
print '<tr><td class="fieldrequired">'.$langs->trans('RefSupplier').'</td><td><input name="ref_supplier" value="'.(isset($_POST['ref_supplier'])?$_POST['ref_supplier']:'').'" type="text"></td>';
print '</tr>';
// Type
// Type invoice
$facids = $facturestatic->list_replacable_supplier_invoices($societe->id);
if ($facids < 0) {
dol_print_error($db, $facturestatic);
exit();
}
$options = "";
foreach ($facids as $facparam)
{
$options .= '<option value="' . $facparam ['id'] . '"';
if ($facparam ['id'] == $_POST['fac_replacement'])
$options .= ' selected';
$options .= '>' . $facparam ['ref'];
$options .= ' (' . $facturestatic->LibStatut(0, $facparam ['status']) . ')';
$options .= '</option>';
}
// Show link for credit note
$facids=$facturestatic->list_qualified_avoir_supplier_invoices($societe->id);
if ($facids < 0)
{
dol_print_error($db,$facturestatic);
exit;
}
$optionsav = "";
$newinvoice_static = new FactureFournisseur($db);
foreach ($facids as $key => $valarray)
{
$newinvoice_static->id = $key;
$newinvoice_static->ref = $valarray ['ref'];
$newinvoice_static->statut = $valarray ['status'];
$newinvoice_static->type = $valarray ['type'];
$newinvoice_static->paye = $valarray ['paye'];
$optionsav .= '<option value="' . $key . '"';
if ($key == GETPOST('fac_avoir','int'))
$optionsav .= ' selected';
$optionsav .= '>';
$optionsav .= $newinvoice_static->ref;
$optionsav .= ' (' . $newinvoice_static->getLibStatut(1, $valarray ['paymentornot']) . ')';
$optionsav .= '</option>';
}
print '<tr><td valign="top" class="fieldrequired">'.$langs->trans('Type').'</td><td colspan="2">';
print '<table class="nobordernopadding">'."\n";
print '<div class="tagtable">' . "\n";
// Standard invoice
print '<tr height="18"><td width="16px" valign="middle">';
print '<input type="radio" name="type" value="0"'.($_POST['type']==0?' checked':'').'>';
print '</td><td valign="middle">';
$desc=$form->textwithpicto($langs->trans("InvoiceStandardAsk"),$langs->transnoentities("InvoiceStandardDesc"),1);
print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
$tmp='<input type="radio" id="radio_standard" name="type" value="0"' . (GETPOST('type') == 0 ? ' checked' : '') . '> ';
$desc = $form->textwithpicto($tmp.$langs->trans("InvoiceStandardAsk"), $langs->transnoentities("InvoiceStandardDesc"), 1, 'help', '', 0, 3);
print $desc;
print '</td></tr>'."\n";
/*
print '</div></div>';
if ((empty($origin)) || ((($origin == 'propal') || ($origin == 'commande')) && (! empty($originid))))
{
// Deposit
print '<tr height="18"><td width="16px" valign="middle">';
print '<input type="radio" name="type" value="3"'.($_POST['type']==3?' checked':'').'>';
print '</td><td valign="middle">';
$desc=$form->textwithpicto($langs->trans("InvoiceDeposit"),$langs->transnoentities("InvoiceDepositDesc"),1);
print $desc;
print '</td></tr>'."\n";
// Proforma
if (! empty($conf->global->FACTURE_USE_PROFORMAT))
{
print '<tr height="18"><td width="16px" valign="middle">';
print '<input type="radio" name="type" value="4"'.($_POST['type']==4?' checked':'').'>';
print '</td><td valign="middle">';
$desc=$form->textwithpicto($langs->trans("InvoiceProForma"),$langs->transnoentities("InvoiceProFormaDesc"),1);
if (empty($conf->global->INVOICE_DISABLE_DEPOSIT))
{
print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
$tmp='<input type="radio" id="radio_deposit" name="type" value="3"' . (GETPOST('type') == 3 ? ' checked' : '') . '> ';
print '<script type="text/javascript" language="javascript">
jQuery(document).ready(function() {
jQuery("#typedeposit, #valuedeposit").click(function() {
jQuery("#radio_deposit").prop("checked", true);
});
});
</script>';
$desc = $form->textwithpicto($tmp.$langs->trans("InvoiceDeposit"), $langs->transnoentities("InvoiceDepositDesc"), 1, 'help', '', 0, 3);
print '<table class="nobordernopadding"><tr><td>';
print $desc;
print '</td></tr>'."\n";
print '</td>';
if (($origin == 'propal') || ($origin == 'commande'))
{
print '<td class="nowrap" style="padding-left: 5px">';
$arraylist = array('amount' => 'FixAmount','variable' => 'VarAmount');
print $form->selectarray('typedeposit', $arraylist, GETPOST('typedeposit'), 0, 0, 0, '', 1);
print '</td>';
print '<td class="nowrap" style="padding-left: 5px">' . $langs->trans('Value') . ':<input type="text" id="valuedeposit" name="valuedeposit" size="3" value="' . GETPOST('valuedeposit', 'int') . '"/>';
}
print '</td></tr></table>';
print '</div></div>';
}
}
if ($societe->id > 0)
{
// Replacement
print '<tr height="18"><td valign="middle">';
print '<input type="radio" name="type" value="1"'.($_POST['type']==1?' checked':'');
if (! $options) print ' disabled';
print '>';
print '</td><td valign="middle">';
$text=$langs->trans("InvoiceReplacementAsk").' ';
$text.='<select class="flat" name="fac_replacement"';
if (! $options) $text.=' disabled';
if (empty($conf->global->INVOICE_DISABLE_REPLACEMENT))
{
print '<!-- replacement line -->';
print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
$tmp='<input type="radio" name="type" id="radio_replacement" value="1"' . (GETPOST('type') == 1 ? ' checked' : '');
if (! $options) $tmp.=' disabled';
$tmp.='> ';
print '<script type="text/javascript" language="javascript">
jQuery(document).ready(function() {
jQuery("#fac_replacement").change(function() {
jQuery("#radio_replacement").prop("checked", true);
});
});
</script>';
$text = $tmp.$langs->trans("InvoiceReplacementAsk") . ' ';
$text .= '<select class="flat" name="fac_replacement" id="fac_replacement"';
if (! $options)
$text .= ' disabled';
$text .= '>';
if ($options)
{
if ($options) {
$text .= '<option value="-1">&nbsp;</option>';
$text .= $options;
}
else
{
} else {
$text .= '<option value="-1">' . $langs->trans("NoReplacableInvoice") . '</option>';
}
$text .= '</select>';
$desc=$form->textwithpicto($text,$langs->transnoentities("InvoiceReplacementDesc"),1);
$desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceReplacementDesc"), 1, 'help', '', 0, 3);
print $desc;
print '</td></tr>';
print '</div></div>';
}
}
else
{
print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
$tmp='<input type="radio" name="type" id="radio_replacement" value="0" disabled> ';
$text = $tmp.$langs->trans("InvoiceReplacement") . ' ';
$text.= '('.$langs->trans("YouMustCreateInvoiceFromSupplierThird").') ';
$desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceReplacementDesc"), 1, 'help', '', 0, 3);
print $desc;
print '</div></div>';
}
if (empty($origin))
{
if ($societe->id > 0)
{
// Credit note
print '<tr height="18"><td valign="middle">';
print '<input type="radio" name="type" value="2"'.($_POST['type']==2?' checked':'');
if (! $optionsav) print ' disabled';
print '>';
print '</td><td valign="middle">';
$text=$langs->transnoentities("InvoiceAvoirAsk").' ';
if (empty($conf->global->INVOICE_DISABLE_CREDIT_NOTE))
{
print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
$tmp='<input type="radio" id="radio_creditnote" name="type" value="2"' . (GETPOST('type') == 2 ? ' checked' : '');
if (! $optionsav) $tmp.=' disabled';
$tmp.= '> ';
// Show credit note options only if we checked credit note
print '<script type="text/javascript" language="javascript">
jQuery(document).ready(function() {
if (! jQuery("#radio_creditnote").is(":checked"))
{
jQuery("#credit_note_options").hide();
}
jQuery("#radio_creditnote").click(function() {
jQuery("#credit_note_options").show();
});
jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() {
jQuery("#credit_note_options").hide();
});
});
</script>';
$text = $tmp.$langs->transnoentities("InvoiceAvoirAsk") . ' ';
// $text.='<input type="text" value="">';
$text.='<select class="flat" name="fac_avoir"';
if (! $optionsav) $text.=' disabled';
$text .= '<select class="flat" name="fac_avoir" id="fac_avoir"';
if (! $optionsav)
$text .= ' disabled';
$text .= '>';
if ($optionsav)
{
$text.='<option value="-1">&nbsp;</option>';
if ($optionsav) {
$text .= '<option value="-1"></option>';
$text .= $optionsav;
}
else
{
} else {
$text .= '<option value="-1">' . $langs->trans("NoInvoiceToCorrect") . '</option>';
}
$text .= '</select>';
$desc=$form->textwithpicto($text,$langs->transnoentities("InvoiceAvoirDesc"),1);
$desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceAvoirDesc"), 1, 'help', '', 0, 3);
print $desc;
print '</td></tr>'."\n";
*/
print '</table>';
print '<div id="credit_note_options" class="clearboth">';
print '&nbsp;&nbsp;&nbsp; <input data-role="none" type="checkbox" name="invoiceAvoirWithLines" id="invoiceAvoirWithLines" value="1" onclick="if($(this).is(\':checked\') ) { $(\'#radio_creditnote\').prop(\'checked\', true); $(\'#invoiceAvoirWithPaymentRestAmount\').removeAttr(\'checked\'); }" '.(GETPOST('invoiceAvoirWithLines','int')>0 ? 'checked':'').' /> <label for="invoiceAvoirWithLines">'.$langs->trans('invoiceAvoirWithLines')."</label>";
print '<br>&nbsp;&nbsp;&nbsp; <input data-role="none" type="checkbox" name="invoiceAvoirWithPaymentRestAmount" id="invoiceAvoirWithPaymentRestAmount" value="1" onclick="if($(this).is(\':checked\') ) { $(\'#radio_creditnote\').prop(\'checked\', true); $(\'#invoiceAvoirWithLines\').removeAttr(\'checked\'); }" '.(GETPOST('invoiceAvoirWithPaymentRestAmount','int')>0 ? 'checked':'').' /> <label for="invoiceAvoirWithPaymentRestAmount">'.$langs->trans('invoiceAvoirWithPaymentRestAmount')."</label>";
print '</div>';
print '</div></div>';
}
}
else
{
print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
$tmp='<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
$text = $tmp.$langs->trans("InvoiceAvoir") . ' ';
$text.= '('.$langs->trans("YouMustCreateInvoiceFromSupplierThird").') ';
$desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceAvoirDesc"), 1, 'help', '', 0, 3);
print $desc;
print '</div></div>' . "\n";
}
}
print '</div>';
print '</td></tr>';
if ($socid > 0)
{
// Discounts for third party
print '<tr><td>' . $langs->trans('Discounts') . '</td><td colspan="2">';
if ($soc->remise_percent)
print $langs->trans("CompanyHasRelativeDiscount", '<a href="' . DOL_URL_ROOT . '/comm/remise.php?id=' . $soc->id . '&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?socid=' . $soc->id . '&action=' . $action . '&origin=' . GETPOST('origin') . '&originid=' . GETPOST('originid')) . '">' . $soc->remise_percent . '</a>');
else
print $langs->trans("CompanyHasNoRelativeDiscount");
print ' <a href="' . DOL_URL_ROOT . '/comm/remise.php?id=' . $soc->id . '&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?socid=' . $soc->id . '&action=' . $action . '&origin=' . GETPOST('origin') . '&originid=' . GETPOST('originid')) . '">(' . $langs->trans("EditRelativeDiscount") . ')</a>';
print '. ';
print '<br>';
if ($absolute_discount)
print $langs->trans("CompanyHasAbsoluteDiscount", '<a href="' . DOL_URL_ROOT . '/comm/remx.php?id=' . $soc->id . '&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?socid=' . $soc->id . '&action=' . $action . '&origin=' . GETPOST('origin') . '&originid=' . GETPOST('originid')) . '">' . price($absolute_discount) . '</a>', $langs->trans("Currency" . $conf->currency));
else
print $langs->trans("CompanyHasNoAbsoluteDiscount");
print ' <a href="' . DOL_URL_ROOT . '/comm/remx.php?id=' . $soc->id . '&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?socid=' . $soc->id . '&action=' . $action . '&origin=' . GETPOST('origin') . '&originid=' . GETPOST('originid')) . '">(' . $langs->trans("EditGlobalDiscounts") . ')</a>';
print '.';
print '</td></tr>';
}
// Label
print '<tr><td>'.$langs->trans('Label').'</td><td><input size="30" name="label" value="'.dol_escape_htmltag(GETPOST('label')).'" type="text"></td></tr>';
......@@ -1646,7 +1789,6 @@ else
// Supplier invoice card
$linkback = '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
$morehtmlref='<div class="refidno">';
......@@ -1693,14 +1835,12 @@ else
dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
print '<div class="fichecenter">';
print '<div class="fichehalfleft">';
print '<div class="underbanner clearboth"></div>';
print '<table class="border" width="100%">';
// Ref
/*
print '<tr><td class="titlefield nowrap">'.$langs->trans("Ref").'</td><td colspan="4">';
......@@ -2263,6 +2403,15 @@ else
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=clone&amp;socid='.$object->socid.'">'.$langs->trans('ToClone').'</a>';
}
// Create a credit note
if (($object->type == FactureFournisseur::TYPE_STANDARD || $object->type == FactureFournisseur::TYPE_DEPOSIT) && $object->statut > 0 && $user->rights->fournisseur->facture->creer)
{
if (! $objectidnext)
{
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?socid=' . $object->socid .'&amp;fac_avoir=' . $object->id . '&amp;action=create&amp;type=2'.($object->fk_project > 0 ? '&amp;projectid='.$object->fk_project : '').'">' . $langs->trans("CreateCreditNote") . '</a></div>';
}
}
// Delete
if ($action != 'edit' && $user->rights->fournisseur->facture->supprimer)
{
......
......@@ -438,6 +438,7 @@ ListOfYourUnpaidInvoices=List of unpaid invoices
NoteListOfYourUnpaidInvoices=Note: This list contains only invoices for third parties you are linked to as a sale representative.
RevenueStamp=Revenue stamp
YouMustCreateInvoiceFromThird=This option is only available when creating invoice from tab "customer" of thirdparty
YouMustCreateInvoiceFromSupplierThird=This option is only available when creating invoice from tab "supplier" of thirdparty
YouMustCreateStandardInvoiceFirstDesc=You have to create a standard invoice first and convert it to "template" to create a new template invoice
PDFCrabeDescription=Invoice PDF template Crabe. A complete invoice template (recommended Template)
PDFCrevetteDescription=Invoice PDF template Crevette. A complete invoice template for situation invoices
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment