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 // Source facture
$object->fac_rec = GETPOST('fac_rec'); $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>'; </script>';
$text = $tmp.$langs->transnoentities("InvoiceAvoirAsk") . ' '; $text = $tmp.$langs->transnoentities("InvoiceAvoirAsk") . ' ';
// $text.='<input type="text" value="">'; // $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) if (! $optionsav)
$text .= ' disabled'; $text .= ' disabled';
$text .= '>'; $text .= '>';

View File

@ -219,9 +219,9 @@ class Facture extends CommonInvoice
} }
/** /**
* Create invoice in database * Create invoice in database.
* Note: this->ref can be set or empty. If empty, we will use "(PROV)" * Note: this->ref can be set or empty. If empty, we will use "(PROV999)"
* Note: this->fac_rec must be set to create from recurring invoice * Note: this->fac_rec must be set to create invoice from a recurring invoice
* *
* @param User $user Object user that create * @param User $user Object user that create
* @param int $notrigger 1=Does not execute triggers, 0 otherwise * @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'; require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php';
$_facrec = new FactureRec($this->db); $_facrec = new FactureRec($this->db);
$result=$_facrec->fetch($this->fac_rec); $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->socid = $_facrec->socid; // Invoice created on same thirdparty than template
$this->entity = $_facrec->entity; // Invoice created in same entity 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; if (! $this->mode_reglement_id) $this->mode_reglement_id = 0;
$this->brouillon = 1; $this->brouillon = 1;
$this->linked_objects = $_facrec->linkedObjectsIds;
var_dump($this->linked_objects);
$forceduedate = $this->calculate_date_lim_reglement(); $forceduedate = $this->calculate_date_lim_reglement();
// For recurring invoices, update date and number of last generation of recurring template invoice, before inserting new invoice // For recurring invoices, update date and number of last generation of recurring template invoice, before inserting new invoice
@ -404,7 +408,11 @@ class Facture extends CommonInvoice
// Add object linked // Add object linked
if (! $error && $this->id && is_array($this->linked_objects) && ! empty($this->linked_objects)) 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)
{
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); $ret = $this->add_object_linked($origin, $origin_id);
if (! $ret) if (! $ret)
@ -412,6 +420,18 @@ class Facture extends CommonInvoice
dol_print_error($this->db); dol_print_error($this->db);
$error++; $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)) if (! empty($conf->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN))
{ {

View File

@ -87,11 +87,11 @@ if (($id > 0 || $ref) && $action != 'create' && $action != 'add')
} }
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('invoicecard','globalcard')); $hookmanager->initHooks(array('invoicereccard','globalcard'));
$extrafields = new ExtraFields($db); $extrafields = new ExtraFields($db);
// fetch optionals attributes and labels // fetch optionals attributes and labels
$extralabels = $extrafields->fetch_name_optionals_label('facturerec'); $extralabels = $extrafields->fetch_name_optionals_label('facture');
$search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_'); $search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_');
$permissionnote = $user->rights->facture->creer; // Used by the include of actions_setnotes.inc.php $permissionnote = $user->rights->facture->creer; // Used by the include of actions_setnotes.inc.php
@ -124,16 +124,42 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab
* Actions * Actions
*/ */
// Set note $parameters = array('socid' => $socid);
include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once if (empty($reshook))
if (GETPOST('cancel')) $action='';
// Create predefined invoice
if ($action == 'add')
{ {
if (GETPOST('cancel')) $action='';
// Set note
include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once
include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once
// Do we click on purge search criteria ?
if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // All test are required to be compatible with all browsers
{
$search_ref='';
$search_societe='';
$search_montant_ht='';
$search_montant_vat='';
$search_montant_ttc='';
$day='';
$year='';
$month='';
$day_date_when='';
$year_date_when='';
$month_date_when='';
$search_frequency='';
$search_array_options=array();
}
// Create predefined invoice
if ($action == 'add')
{
if (! GETPOST('titre')) if (! GETPOST('titre'))
{ {
setEventMessages($langs->transnoentities("ErrorFieldRequired",$langs->trans("Title")), null, 'errors'); setEventMessages($langs->transnoentities("ErrorFieldRequired",$langs->trans("Title")), null, 'errors');
@ -240,74 +266,74 @@ if ($action == 'add')
$action = "create"; $action = "create";
} }
} }
} }
// Delete // Delete
if ($action == 'confirm_deleteinvoice' && $confirm == 'yes' && $user->rights->facture->supprimer) if ($action == 'confirm_deleteinvoice' && $confirm == 'yes' && $user->rights->facture->supprimer)
{ {
$object->delete(); $object->delete();
header("Location: " . $_SERVER['PHP_SELF'] ); header("Location: " . $_SERVER['PHP_SELF'] );
exit; exit;
} }
// Update field // Update field
// Set condition // Set condition
if ($action == 'setconditions' && $user->rights->facture->creer) if ($action == 'setconditions' && $user->rights->facture->creer)
{ {
$result=$object->setPaymentTerms(GETPOST('cond_reglement_id', 'int')); $result=$object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'));
} }
// Set mode // Set mode
elseif ($action == 'setmode' && $user->rights->facture->creer) elseif ($action == 'setmode' && $user->rights->facture->creer)
{ {
$result=$object->setPaymentMethods(GETPOST('mode_reglement_id', 'int')); $result=$object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));
} }
// Set project // Set project
elseif ($action == 'classin' && $user->rights->facture->creer) elseif ($action == 'classin' && $user->rights->facture->creer)
{ {
$object->setProject(GETPOST('projectid', 'int')); $object->setProject(GETPOST('projectid', 'int'));
} }
// Set bank account // Set bank account
elseif ($action == 'setref' && $user->rights->facture->creer) elseif ($action == 'setref' && $user->rights->facture->creer)
{ {
$result=$object->setValueFrom('titre', GETPOST('ref', 'alpha'), '', null, 'text', '', $user, 'BILLREC_MODIFY'); $result=$object->setValueFrom('titre', GETPOST('ref', 'alpha'), '', null, 'text', '', $user, 'BILLREC_MODIFY');
if ($result > 0) if ($result > 0)
{ {
$object->titre = GETPOST('ref', 'alpha'); $object->titre = GETPOST('ref', 'alpha');
$object->ref = $object->titre; $object->ref = $object->titre;
} }
} }
// Set bank account // Set bank account
elseif ($action == 'setbankaccount' && $user->rights->facture->creer) elseif ($action == 'setbankaccount' && $user->rights->facture->creer)
{ {
$result=$object->setBankAccount(GETPOST('fk_account', 'int')); $result=$object->setBankAccount(GETPOST('fk_account', 'int'));
} }
// Set frequency and unit frequency // Set frequency and unit frequency
elseif ($action == 'setfrequency' && $user->rights->facture->creer) elseif ($action == 'setfrequency' && $user->rights->facture->creer)
{ {
$object->setFrequencyAndUnit(GETPOST('frequency', 'int'), GETPOST('unit_frequency', 'alpha')); $object->setFrequencyAndUnit(GETPOST('frequency', 'int'), GETPOST('unit_frequency', 'alpha'));
} }
// Set next date of execution // Set next date of execution
elseif ($action == 'setdate_when' && $user->rights->facture->creer) elseif ($action == 'setdate_when' && $user->rights->facture->creer)
{ {
$date = dol_mktime(GETPOST('date_whenhour'), GETPOST('date_whenmin'), 0, GETPOST('date_whenmonth'), GETPOST('date_whenday'), GETPOST('date_whenyear')); $date = dol_mktime(GETPOST('date_whenhour'), GETPOST('date_whenmin'), 0, GETPOST('date_whenmonth'), GETPOST('date_whenday'), GETPOST('date_whenyear'));
if (!empty($date)) $object->setNextDate($date); if (!empty($date)) $object->setNextDate($date);
} }
// Set max period // Set max period
elseif ($action == 'setnb_gen_max' && $user->rights->facture->creer) elseif ($action == 'setnb_gen_max' && $user->rights->facture->creer)
{ {
$object->setMaxPeriod(GETPOST('nb_gen_max', 'int')); $object->setMaxPeriod(GETPOST('nb_gen_max', 'int'));
} }
// Set auto validate // Set auto validate
elseif ($action == 'setauto_validate' && $user->rights->facture->creer) elseif ($action == 'setauto_validate' && $user->rights->facture->creer)
{ {
$object->setAutoValidate(GETPOST('auto_validate', 'int')); $object->setAutoValidate(GETPOST('auto_validate', 'int'));
} }
// Delete line // Delete line
if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->facture->creer) if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->facture->creer)
{ {
$object->fetch($id); $object->fetch($id);
$object->fetch_thirdparty(); $object->fetch_thirdparty();
@ -338,11 +364,11 @@ if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->factu
$db->rollback(); $db->rollback();
setEventMessages($line->error, $line->errors, 'errors'); setEventMessages($line->error, $line->errors, 'errors');
} }
} }
// Add a new line // Add a new line
if ($action == 'addline' && $user->rights->facture->creer) if ($action == 'addline' && $user->rights->facture->creer)
{ {
$langs->load('errors'); $langs->load('errors');
$error = 0; $error = 0;
@ -644,10 +670,10 @@ if ($action == 'addline' && $user->rights->facture->creer)
$action = ''; $action = '';
} }
} }
} }
elseif ($action == 'updateligne' && $user->rights->facture->creer && ! GETPOST('cancel')) elseif ($action == 'updateligne' && $user->rights->facture->creer && ! GETPOST('cancel'))
{ {
if (! $object->fetch($id) > 0) dol_print_error($db); if (! $object->fetch($id) > 0) dol_print_error($db);
$object->fetch_thirdparty(); $object->fetch_thirdparty();
@ -825,27 +851,9 @@ elseif ($action == 'updateligne' && $user->rights->facture->creer && ! GETPOST('
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
} }
} }
}
} }
// Do we click on purge search criteria ?
if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // All test are required to be compatible with all browsers
{
$search_ref='';
$search_societe='';
$search_montant_ht='';
$search_montant_vat='';
$search_montant_ttc='';
$day='';
$year='';
$month='';
$day_date_when='';
$year_date_when='';
$month_date_when='';
$search_frequency='';
$search_array_options=array();
}
/* /*
* View * View
@ -1420,8 +1428,9 @@ else
// Show links to link elements // Show links to link elements
//$linktoelem = $form->showLinkToObjectBlock($object, null, array('order')); $linktoelem = $form->showLinkToObjectBlock($object, null, array('invoice'));
$somethingshown = $form->showLinkedObjectBlock($object, '');
$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
print '</div></div>'; print '</div></div>';

View File

@ -1322,6 +1322,7 @@ if ($action == 'create')
print $desc; print $desc;
print '</div></div>'; print '</div></div>';
/* Not yet supported
if ((empty($origin)) || ((($origin == 'propal') || ($origin == 'commande')) && (! empty($originid)))) if ((empty($origin)) || ((($origin == 'propal') || ($origin == 'commande')) && (! empty($originid))))
{ {
// Deposit // Deposit
@ -1354,7 +1355,9 @@ if ($action == 'create')
print '</div></div>'; print '</div></div>';
} }
} }
*/
/* Not yet supporter for supplier
if ($societe->id > 0) if ($societe->id > 0)
{ {
// Replacement // Replacement
@ -1399,8 +1402,11 @@ if ($action == 'create')
print $desc; print $desc;
print '</div></div>'; print '</div></div>';
} }
*/
if (empty($origin)) if (empty($origin))
{
if ($conf->global->MAIN_FEATURES_LEVEL > 0) // Need to fix reports of standard accounting module to manage supplier credit note
{ {
if ($societe->id > 0) if ($societe->id > 0)
{ {
@ -1428,7 +1434,7 @@ if ($action == 'create')
</script>'; </script>';
$text = $tmp.$langs->transnoentities("InvoiceAvoirAsk") . ' '; $text = $tmp.$langs->transnoentities("InvoiceAvoirAsk") . ' ';
// $text.='<input type="text" value="">'; // $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) if (! $optionsav)
$text .= ' disabled'; $text .= ' disabled';
$text .= '>'; $text .= '>';
@ -1461,6 +1467,7 @@ if ($action == 'create')
print '</div></div>' . "\n"; print '</div></div>' . "\n";
} }
} }
}
print '</div>'; print '</div>';