NEW Can link template invoice to other objects. Generated invoice will

be linked to same objects.
This commit is contained in:
Laurent Destailleur 2016-10-04 11:14:00 +02:00
parent 2f7bdbaab3
commit d81cd7ebbe
4 changed files with 823 additions and 787 deletions

View File

@ -894,7 +894,7 @@ if (empty($reshook))
// Source facture
$object->fac_rec = GETPOST('fac_rec');
$id = $object->create($user);
$id = $object->create($user); // This include recopy of links from recurring invoice
}
}
@ -2319,7 +2319,7 @@ if ($action == 'create')
</script>';
$text = $tmp.$langs->transnoentities("InvoiceAvoirAsk") . ' ';
// $text.='<input type="text" value="">';
$text .= '<select class="flat" name="fac_avoir" id="fac_avoir"';
$text .= '<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
if (! $optionsav)
$text .= ' disabled';
$text .= '>';
@ -2352,7 +2352,7 @@ if ($action == 'create')
print '</div></div>' . "\n";
}
}
// Template invoice
print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
$tmp='<input type="radio" name="type" id="radio_template" value="0" disabled> ';

View File

@ -219,9 +219,9 @@ class Facture extends CommonInvoice
}
/**
* Create invoice in database
* Note: this->ref can be set or empty. If empty, we will use "(PROV)"
* Note: this->fac_rec must be set to create from recurring invoice
* Create invoice in database.
* Note: this->ref can be set or empty. If empty, we will use "(PROV999)"
* Note: this->fac_rec must be set to create invoice from a recurring invoice
*
* @param User $user Object user that create
* @param int $notrigger 1=Does not execute triggers, 0 otherwise
@ -282,6 +282,7 @@ class Facture extends CommonInvoice
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php';
$_facrec = new FactureRec($this->db);
$result=$_facrec->fetch($this->fac_rec);
$result=$_facrec->fetchObjectLinked(); // This load $_facrec->linkedObjectsIds
$this->socid = $_facrec->socid; // Invoice created on same thirdparty than template
$this->entity = $_facrec->entity; // Invoice created in same entity than template
@ -312,6 +313,9 @@ class Facture extends CommonInvoice
if (! $this->mode_reglement_id) $this->mode_reglement_id = 0;
$this->brouillon = 1;
$this->linked_objects = $_facrec->linkedObjectsIds;
var_dump($this->linked_objects);
$forceduedate = $this->calculate_date_lim_reglement();
// For recurring invoices, update date and number of last generation of recurring template invoice, before inserting new invoice
@ -404,15 +408,31 @@ class Facture extends CommonInvoice
// Add object linked
if (! $error && $this->id && is_array($this->linked_objects) && ! empty($this->linked_objects))
{
foreach($this->linked_objects as $origin => $origin_id)
foreach($this->linked_objects as $origin => $tmp_origin_id)
{
$ret = $this->add_object_linked($origin, $origin_id);
if (! $ret)
{
dol_print_error($this->db);
$error++;
}
if (is_array($tmp_origin_id)) // New baheviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...))
{
foreach($tmp_origin_id as $origin_id)
{
$ret = $this->add_object_linked($origin, $origin_id);
if (! $ret)
{
dol_print_error($this->db);
$error++;
}
}
}
else // Old behaviour, if linked_object has only one link per type, so is something like array('contract'=>id1))
{
$origin_id = $tmp_origin_id;
$ret = $this->add_object_linked($origin, $origin_id);
if (! $ret)
{
dol_print_error($this->db);
$error++;
}
}
if (! empty($conf->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN))
{
$originforcontact = $origin;

File diff suppressed because it is too large Load Diff

View File

@ -1322,6 +1322,7 @@ if ($action == 'create')
print $desc;
print '</div></div>';
/* Not yet supported
if ((empty($origin)) || ((($origin == 'propal') || ($origin == 'commande')) && (! empty($originid))))
{
// Deposit
@ -1354,7 +1355,9 @@ if ($action == 'create')
print '</div></div>';
}
}
*/
/* Not yet supporter for supplier
if ($societe->id > 0)
{
// Replacement
@ -1399,67 +1402,71 @@ if ($action == 'create')
print $desc;
print '</div></div>';
}
*/
if (empty($origin))
{
if ($societe->id > 0)
{
// Credit note
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" id="fac_avoir"';
if (! $optionsav)
$text .= ' disabled';
$text .= '>';
if ($optionsav) {
$text .= '<option value="-1"></option>';
$text .= $optionsav;
} else {
$text .= '<option value="-1">' . $langs->trans("NoInvoiceToCorrect") . '</option>';
}
$text .= '</select>';
$desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceAvoirDesc"), 1, 'help', '', 0, 3);
print $desc;
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";
}
if ($conf->global->MAIN_FEATURES_LEVEL > 0) // Need to fix reports of standard accounting module to manage supplier credit note
{
if ($societe->id > 0)
{
// Credit note
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 valignmiddle" name="fac_avoir" id="fac_avoir"';
if (! $optionsav)
$text .= ' disabled';
$text .= '>';
if ($optionsav) {
$text .= '<option value="-1"></option>';
$text .= $optionsav;
} else {
$text .= '<option value="-1">' . $langs->trans("NoInvoiceToCorrect") . '</option>';
}
$text .= '</select>';
$desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceAvoirDesc"), 1, 'help', '', 0, 3);
print $desc;
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>';