From a328e673a3b7dd707f0b9592f8d8d1428446d147 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Sun, 2 Oct 2016 21:39:24 +0200 Subject: [PATCH] Work on supplier type (Replacement / deposit / credit note) invoice --- .../fourn/class/fournisseur.facture.class.php | 5 + htdocs/fourn/facture/card.php | 367 ++++++++++++------ htdocs/langs/en_US/bills.lang | 1 + 3 files changed, 264 insertions(+), 109 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 865cc4336f0..31022d83965 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -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 * diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index 2e0ef64f96f..5c6f21194a6 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -6,8 +6,9 @@ * Copyright (C) 2005-2013 Regis Houssin * Copyright (C) 2010-2014 Juanjo Menent * Copyright (C) 2013-2015 Philippe Grand - * Copyright (C) 2013 Florian Henry - * Copyright (C) 2014 Marcos García + * Copyright (C) 2013 Florian Henry + * Copyright (C) 2014 Marcos García + * Copyright (C) 2016 Alexandre Spangaro * * 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'); +$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)); @@ -1152,22 +1156,22 @@ if ($action == 'create') $currency_code = $conf->currency; - $societe=''; - if (GETPOST('socid') > 0) - { - $societe=new Societe($db); - $societe->fetch(GETPOST('socid','int')); + $societe=''; + if (GETPOST('socid') > 0) + { + $societe=new Societe($db); + $societe->fetch(GETPOST('socid','int')); 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'))) @@ -1190,7 +1194,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:''); @@ -1229,12 +1233,12 @@ if ($action == 'create') if (!empty($conf->multicurrency->enabled) && !empty($soc->multicurrency_code)) $currency_code = $soc->multicurrency_code; } - print '
'; print ''; print ''; - print ''; - print ''; + if ($societe->id > 0) print '' . "\n"; + print ''; + print ''; if (!empty($currency_tx)) print ''; dol_fiche_head(); @@ -1248,14 +1252,14 @@ if ($action == 'create') print ''.$langs->trans('Supplier').''; print ''; - if (GETPOST('socid') > 0) + if ($societe->id > 0) { print $societe->getNomUrl(1); - print ''; + print ''; } 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 ''; @@ -1263,84 +1267,223 @@ if ($action == 'create') print ''.$langs->trans('RefSupplier').''; print ''; - // Type - print ''.$langs->trans('Type').''; - print ''."\n"; - // Standard invoice - print ''."\n"; - /* - // Deposit - print ''."\n"; - // Proforma - if (! empty($conf->global->FACTURE_USE_PROFORMAT)) - { - print ''."\n"; - } - // Replacement - print ''; - // Credit note - print ''."\n"; - */ - print '
'; - print ''; - print ''; - $desc=$form->textwithpicto($langs->trans("InvoiceStandardAsk"),$langs->transnoentities("InvoiceStandardDesc"),1); - print $desc; - print '
'; - print ''; - print ''; - $desc=$form->textwithpicto($langs->trans("InvoiceDeposit"),$langs->transnoentities("InvoiceDepositDesc"),1); - print $desc; - print '
'; - print ''; - print ''; - $desc=$form->textwithpicto($langs->trans("InvoiceProForma"),$langs->transnoentities("InvoiceProFormaDesc"),1); - print $desc; - print '
'; - print ''; - print ''; - $text=$langs->trans("InvoiceReplacementAsk").' '; - $text.=''; - $desc=$form->textwithpicto($text,$langs->transnoentities("InvoiceReplacementDesc"),1); - print $desc; - print '
'; - print ''; - print ''; - $text=$langs->transnoentities("InvoiceAvoirAsk").' '; - // $text.=''; - $text.=''; - $desc=$form->textwithpicto($text,$langs->transnoentities("InvoiceAvoirDesc"),1); - print $desc; - print '
'; - print ''; + // 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 .= ''; + } + + // 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 .= ''; + } + + print ''.$langs->trans('Type').''; + + print '
' . "\n"; + + // Standard invoice + print '
'; + $tmp=' '; + $desc = $form->textwithpicto($tmp.$langs->trans("InvoiceStandardAsk"), $langs->transnoentities("InvoiceStandardDesc"), 1, 'help', '', 0, 3); + print $desc; + print '
'; + + if ((empty($origin)) || ((($origin == 'propal') || ($origin == 'commande')) && (! empty($originid)))) + { + // Deposit + if (empty($conf->global->INVOICE_DISABLE_DEPOSIT)) + { + print '
'; + $tmp=' '; + print ''; + + $desc = $form->textwithpicto($tmp.$langs->trans("InvoiceDeposit"), $langs->transnoentities("InvoiceDepositDesc"), 1, 'help', '', 0, 3); + print ''; + if (($origin == 'propal') || ($origin == 'commande')) + { + print ''; + print '
'; + print $desc; + print ''; + $arraylist = array('amount' => 'FixAmount','variable' => 'VarAmount'); + print $form->selectarray('typedeposit', $arraylist, GETPOST('typedeposit'), 0, 0, 0, '', 1); + print '' . $langs->trans('Value') . ':'; + } + print '
'; + + print '
'; + } + } + + if ($societe->id > 0) + { + // Replacement + if (empty($conf->global->INVOICE_DISABLE_REPLACEMENT)) + { + print ''; + print '
'; + $tmp=' + jQuery(document).ready(function() { + jQuery("#fac_replacement").change(function() { + jQuery("#radio_replacement").prop("checked", true); + }); + }); + '; + $text = $tmp.$langs->trans("InvoiceReplacementAsk") . ' '; + $text .= ''; + $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceReplacementDesc"), 1, 'help', '', 0, 3); + print $desc; + print '
'; + } + } + else + { + print '
'; + $tmp=' '; + $text = $tmp.$langs->trans("InvoiceReplacement") . ' '; + $text.= '('.$langs->trans("YouMustCreateInvoiceFromSupplierThird").') '; + $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceReplacementDesc"), 1, 'help', '', 0, 3); + print $desc; + print '
'; + } + + if (empty($origin)) + { + if ($societe->id > 0) + { + // Credit note + if (empty($conf->global->INVOICE_DISABLE_CREDIT_NOTE)) + { + print '
'; + $tmp=' + 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(); + }); + }); + '; + $text = $tmp.$langs->transnoentities("InvoiceAvoirAsk") . ' '; + // $text.=''; + $text .= ''; + $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceAvoirDesc"), 1, 'help', '', 0, 3); + print $desc; + + print '
'; + print '    0 ? 'checked':'').' /> "; + print '
    0 ? 'checked':'').' /> "; + print '
'; + + print '
'; + } + } + else + { + print '
'; + $tmp=' '; + $text = $tmp.$langs->trans("InvoiceAvoir") . ' '; + $text.= '('.$langs->trans("YouMustCreateInvoiceFromSupplierThird").') '; + $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceAvoirDesc"), 1, 'help', '', 0, 3); + print $desc; + print '
' . "\n"; + } + } + + print '
'; + + print ''; + + if ($socid > 0) + { + // Discounts for third party + print '' . $langs->trans('Discounts') . ''; + if ($soc->remise_percent) + print $langs->trans("CompanyHasRelativeDiscount", '' . $soc->remise_percent . ''); + else + print $langs->trans("CompanyHasNoRelativeDiscount"); + print ' (' . $langs->trans("EditRelativeDiscount") . ')'; + print '. '; + print '
'; + if ($absolute_discount) + print $langs->trans("CompanyHasAbsoluteDiscount", '' . price($absolute_discount) . '', $langs->trans("Currency" . $conf->currency)); + else + print $langs->trans("CompanyHasNoAbsoluteDiscount"); + print ' (' . $langs->trans("EditGlobalDiscounts") . ')'; + print '.'; + print ''; + } // Label print ''.$langs->trans('Label').''; @@ -1534,7 +1677,7 @@ else $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $alreadypaid=$object->getSommePaiement(); - + /* * View card */ @@ -1645,9 +1788,8 @@ else // Supplier invoice card - $linkback = ''.$langs->trans("BackToList").''; - + $morehtmlref='
'; // Ref supplier $morehtmlref.=$form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->rights->fournisseur->commande->creer, 'string', '', 0, 1); @@ -1687,18 +1829,16 @@ else } } $morehtmlref.='
'; - + $object->totalpaye = $alreadypaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status - + dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); - - + print '
'; print '
'; print '
'; - + print ''; - // Ref /* @@ -1717,7 +1857,7 @@ else print '   ('.$langs->trans('OtherBills').')'; print ''; */ - + // Type print '
'.$langs->trans('Type').''; print $object->getLibType(); @@ -2262,6 +2402,15 @@ else print 'socid.'">'.$langs->trans('ToClone').''; } + // 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 ''; + } + } + // Delete if ($action != 'edit' && $user->rights->fournisseur->facture->supprimer) { diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index ac27ef018fd..8af385091aa 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -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