Merge pull request #20710 from fappels/develop_confirm_createbills
Move massaction 'confirm_createbills' from actions_massactions.inc.php to commande/list.php
This commit is contained in:
commit
fa8ce6e4fd
@ -34,7 +34,7 @@ Following changes may create regressions for some external modules, but were nec
|
||||
* The deprecated method thirdparty_doc_create() has been removed. You can use the generateDocument() instead.
|
||||
* All triggers with a name XXX_UPDATE have been rename with name XXX_MODIFY for code consistency purpose.
|
||||
* Rename build_path_from_id_categ() into buildPathFromId() and set method to private
|
||||
|
||||
* Move massaction 'confirm_createbills' from actions_massactions.inc.php to commande/list.php
|
||||
|
||||
***** ChangeLog for 15.0.1 compared to 15.0.0 *****
|
||||
FIX: #19777 #20281
|
||||
|
||||
@ -172,7 +172,7 @@ $result = restrictedArea($user, 'adherent');
|
||||
if (GETPOST('cancel', 'alpha')) {
|
||||
$action = 'list'; $massaction = '';
|
||||
}
|
||||
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createbills') {
|
||||
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
|
||||
$massaction = '';
|
||||
}
|
||||
|
||||
|
||||
@ -111,7 +111,7 @@ $result = restrictedArea($user, 'adherent', '', '', 'cotisation');
|
||||
if (GETPOST('cancel', 'alpha')) {
|
||||
$action = 'list'; $massaction = '';
|
||||
}
|
||||
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createbills') {
|
||||
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
|
||||
$massaction = '';
|
||||
}
|
||||
|
||||
|
||||
@ -302,6 +302,352 @@ if (empty($reshook)) {
|
||||
$uploaddir = $conf->commande->multidir_output[$conf->entity];
|
||||
$triggersendname = 'ORDER_SENTBYMAIL';
|
||||
include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
|
||||
|
||||
if ($massaction == 'confirm_createbills') { // Create bills from orders.
|
||||
$orders = GETPOST('toselect', 'array');
|
||||
$createbills_onebythird = GETPOST('createbills_onebythird', 'int');
|
||||
$validate_invoices = GETPOST('validate_invoices', 'int');
|
||||
|
||||
$errors = array();
|
||||
|
||||
$TFact = array();
|
||||
$TFactThird = array();
|
||||
$TFactThirdNbLines = array();
|
||||
|
||||
$nb_bills_created = 0;
|
||||
$lastid= 0;
|
||||
$lastref = '';
|
||||
|
||||
$db->begin();
|
||||
|
||||
foreach ($orders as $id_order) {
|
||||
$cmd = new Commande($db);
|
||||
if ($cmd->fetch($id_order) <= 0) {
|
||||
continue;
|
||||
}
|
||||
$cmd->fetch_thirdparty();
|
||||
|
||||
$objecttmp = new Facture($db);
|
||||
if (!empty($createbills_onebythird) && !empty($TFactThird[$cmd->socid])) {
|
||||
// If option "one bill per third" is set, and an invoice for this thirdparty was already created, we re-use it.
|
||||
$objecttmp = $TFactThird[$cmd->socid];
|
||||
} else {
|
||||
// If we want one invoice per order or if there is no first invoice yet for this thirdparty.
|
||||
$objecttmp->socid = $cmd->socid;
|
||||
$objecttmp->thirdparty = $cmd->thirdparty;
|
||||
|
||||
$objecttmp->type = $objecttmp::TYPE_STANDARD;
|
||||
$objecttmp->cond_reglement_id = !empty($cmd->cond_reglement_id) ? $cmd->cond_reglement_id : $cmd->thirdparty->cond_reglement_id;
|
||||
$objecttmp->mode_reglement_id = !empty($cmd->mode_reglement_id) ? $cmd->mode_reglement_id : $cmd->thirdparty->mode_reglement_id;
|
||||
|
||||
$objecttmp->fk_project = $cmd->fk_project;
|
||||
$objecttmp->multicurrency_code = $cmd->multicurrency_code;
|
||||
if (empty($createbills_onebythird)) {
|
||||
$objecttmp->ref_client = $cmd->ref_client;
|
||||
}
|
||||
|
||||
$datefacture = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
|
||||
if (empty($datefacture)) {
|
||||
$datefacture = dol_now();
|
||||
}
|
||||
|
||||
$objecttmp->date = $datefacture;
|
||||
$objecttmp->origin = 'commande';
|
||||
$objecttmp->origin_id = $id_order;
|
||||
|
||||
$objecttmp->array_options = $cmd->array_options; // Copy extrafields
|
||||
|
||||
$res = $objecttmp->create($user);
|
||||
|
||||
if ($res > 0) {
|
||||
$nb_bills_created++;
|
||||
$lastref = $objecttmp->ref;
|
||||
$lastid = $objecttmp->id;
|
||||
|
||||
$TFactThird[$cmd->socid] = $objecttmp;
|
||||
$TFactThirdNbLines[$cmd->socid] = 0; //init nblines to have lines ordered by expedition and rang
|
||||
} else {
|
||||
$langs->load("errors");
|
||||
$errors[] = $cmd->ref.' : '.$langs->trans($objecttmp->errors[0]);
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($objecttmp->id > 0) {
|
||||
$res = $objecttmp->add_object_linked($objecttmp->origin, $id_order);
|
||||
|
||||
if ($res == 0) {
|
||||
$errors[] = $cmd->ref.' : '.$langs->trans($objecttmp->errors[0]);
|
||||
$error++;
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
$lines = $cmd->lines;
|
||||
if (empty($lines) && method_exists($cmd, 'fetch_lines')) {
|
||||
$cmd->fetch_lines();
|
||||
$lines = $cmd->lines;
|
||||
}
|
||||
|
||||
$fk_parent_line = 0;
|
||||
$num = count($lines);
|
||||
|
||||
for ($i = 0; $i < $num; $i++) {
|
||||
$desc = ($lines[$i]->desc ? $lines[$i]->desc : '');
|
||||
// If we build one invoice for several orders, we must put the ref of order on the invoice line
|
||||
if (!empty($createbills_onebythird)) {
|
||||
$desc = dol_concatdesc($desc, $langs->trans("Order").' '.$cmd->ref.' - '.dol_print_date($cmd->date, 'day'));
|
||||
}
|
||||
|
||||
if ($lines[$i]->subprice < 0) {
|
||||
// Negative line, we create a discount line
|
||||
$discount = new DiscountAbsolute($db);
|
||||
$discount->fk_soc = $objecttmp->socid;
|
||||
$discount->amount_ht = abs($lines[$i]->total_ht);
|
||||
$discount->amount_tva = abs($lines[$i]->total_tva);
|
||||
$discount->amount_ttc = abs($lines[$i]->total_ttc);
|
||||
$discount->tva_tx = $lines[$i]->tva_tx;
|
||||
$discount->fk_user = $user->id;
|
||||
$discount->description = $desc;
|
||||
$discountid = $discount->create($user);
|
||||
if ($discountid > 0) {
|
||||
$result = $objecttmp->insert_discount($discountid);
|
||||
//$result=$discount->link_to_invoice($lineid,$id);
|
||||
} else {
|
||||
setEventMessages($discount->error, $discount->errors, 'errors');
|
||||
$error++;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// Positive line
|
||||
$product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
|
||||
// Date start
|
||||
$date_start = false;
|
||||
if ($lines[$i]->date_debut_prevue) {
|
||||
$date_start = $lines[$i]->date_debut_prevue;
|
||||
}
|
||||
if ($lines[$i]->date_debut_reel) {
|
||||
$date_start = $lines[$i]->date_debut_reel;
|
||||
}
|
||||
if ($lines[$i]->date_start) {
|
||||
$date_start = $lines[$i]->date_start;
|
||||
}
|
||||
//Date end
|
||||
$date_end = false;
|
||||
if ($lines[$i]->date_fin_prevue) {
|
||||
$date_end = $lines[$i]->date_fin_prevue;
|
||||
}
|
||||
if ($lines[$i]->date_fin_reel) {
|
||||
$date_end = $lines[$i]->date_fin_reel;
|
||||
}
|
||||
if ($lines[$i]->date_end) {
|
||||
$date_end = $lines[$i]->date_end;
|
||||
}
|
||||
// Reset fk_parent_line for no child products and special product
|
||||
if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
|
||||
$fk_parent_line = 0;
|
||||
}
|
||||
|
||||
// Extrafields
|
||||
if (method_exists($lines[$i], 'fetch_optionals')) {
|
||||
$lines[$i]->fetch_optionals();
|
||||
$array_options = $lines[$i]->array_options;
|
||||
}
|
||||
|
||||
$objecttmp->context['createfromclone'];
|
||||
|
||||
$rang = $lines[$i]->rang;
|
||||
//there may already be rows from previous orders
|
||||
if (!empty($createbills_onebythird))
|
||||
$rang = $TFactThirdNbLines[$cmd->socid];
|
||||
|
||||
$result = $objecttmp->addline(
|
||||
$desc,
|
||||
$lines[$i]->subprice,
|
||||
$lines[$i]->qty,
|
||||
$lines[$i]->tva_tx,
|
||||
$lines[$i]->localtax1_tx,
|
||||
$lines[$i]->localtax2_tx,
|
||||
$lines[$i]->fk_product,
|
||||
$lines[$i]->remise_percent,
|
||||
$date_start,
|
||||
$date_end,
|
||||
0,
|
||||
$lines[$i]->info_bits,
|
||||
$lines[$i]->fk_remise_except,
|
||||
'HT',
|
||||
0,
|
||||
$product_type,
|
||||
$rang,
|
||||
$lines[$i]->special_code,
|
||||
$objecttmp->origin,
|
||||
$lines[$i]->rowid,
|
||||
$fk_parent_line,
|
||||
$lines[$i]->fk_fournprice,
|
||||
$lines[$i]->pa_ht,
|
||||
$lines[$i]->label,
|
||||
$array_options,
|
||||
100,
|
||||
0,
|
||||
$lines[$i]->fk_unit
|
||||
);
|
||||
if ($result > 0) {
|
||||
$lineid = $result;
|
||||
if (!empty($createbills_onebythird)) //increment rang to keep order
|
||||
$TFactThirdNbLines[$rcp->socid]++;
|
||||
} else {
|
||||
$lineid = 0;
|
||||
$error++;
|
||||
break;
|
||||
}
|
||||
// Defined the new fk_parent_line
|
||||
if ($result > 0 && $lines[$i]->product_type == 9) {
|
||||
$fk_parent_line = $result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//$cmd->classifyBilled($user); // Disabled. This behavior must be set or not using the workflow module.
|
||||
|
||||
if (!empty($createbills_onebythird) && empty($TFactThird[$cmd->socid])) {
|
||||
$TFactThird[$cmd->socid] = $objecttmp;
|
||||
} else {
|
||||
$TFact[$objecttmp->id] = $objecttmp;
|
||||
}
|
||||
}
|
||||
|
||||
// Build doc with all invoices
|
||||
$TAllFact = empty($createbills_onebythird) ? $TFact : $TFactThird;
|
||||
$toselect = array();
|
||||
|
||||
if (!$error && $validate_invoices) {
|
||||
$massaction = $action = 'builddoc';
|
||||
|
||||
foreach ($TAllFact as &$objecttmp) {
|
||||
$result = $objecttmp->validate($user);
|
||||
if ($result <= 0) {
|
||||
$error++;
|
||||
setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
|
||||
break;
|
||||
}
|
||||
|
||||
$id = $objecttmp->id; // For builddoc action
|
||||
|
||||
// Builddoc
|
||||
$donotredirect = 1;
|
||||
$upload_dir = $conf->facture->dir_output;
|
||||
$permissiontoadd = $user->rights->facture->creer;
|
||||
|
||||
// Call action to build doc
|
||||
$savobject = $object;
|
||||
$object = $objecttmp;
|
||||
include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
|
||||
$object = $savobject;
|
||||
}
|
||||
|
||||
$massaction = $action = 'confirm_createbills';
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
$db->commit();
|
||||
|
||||
if ($nb_bills_created == 1) {
|
||||
$texttoshow = $langs->trans('BillXCreated', '{s1}');
|
||||
$texttoshow = str_replace('{s1}', '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?id='.urlencode($lastid).'">'.$lastref.'</a>', $texttoshow);
|
||||
setEventMessages($texttoshow, null, 'mesgs');
|
||||
} else {
|
||||
setEventMessages($langs->trans('BillCreated', $nb_bills_created), null, 'mesgs');
|
||||
}
|
||||
|
||||
// Make a redirect to avoid to bill twice if we make a refresh or back
|
||||
$param = '';
|
||||
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
|
||||
$param .= '&contextpage='.urlencode($contextpage);
|
||||
}
|
||||
if ($limit > 0 && $limit != $conf->liste_limit) {
|
||||
$param .= '&limit='.urlencode($limit);
|
||||
}
|
||||
if ($sall) {
|
||||
$param .= '&sall='.urlencode($sall);
|
||||
}
|
||||
if ($socid > 0) {
|
||||
$param .= '&socid='.urlencode($socid);
|
||||
}
|
||||
if ($search_status != '') {
|
||||
$param .= '&search_status='.urlencode($search_status);
|
||||
}
|
||||
if ($search_orderday) {
|
||||
$param .= '&search_orderday='.urlencode($search_orderday);
|
||||
}
|
||||
if ($search_ordermonth) {
|
||||
$param .= '&search_ordermonth='.urlencode($search_ordermonth);
|
||||
}
|
||||
if ($search_orderyear) {
|
||||
$param .= '&search_orderyear='.urlencode($search_orderyear);
|
||||
}
|
||||
if ($search_deliveryday) {
|
||||
$param .= '&search_deliveryday='.urlencode($search_deliveryday);
|
||||
}
|
||||
if ($search_deliverymonth) {
|
||||
$param .= '&search_deliverymonth='.urlencode($search_deliverymonth);
|
||||
}
|
||||
if ($search_deliveryyear) {
|
||||
$param .= '&search_deliveryyear='.urlencode($search_deliveryyear);
|
||||
}
|
||||
if ($search_ref) {
|
||||
$param .= '&search_ref='.urlencode($search_ref);
|
||||
}
|
||||
if ($search_company) {
|
||||
$param .= '&search_company='.urlencode($search_company);
|
||||
}
|
||||
if ($search_ref_customer) {
|
||||
$param .= '&search_ref_customer='.urlencode($search_ref_customer);
|
||||
}
|
||||
if ($search_user > 0) {
|
||||
$param .= '&search_user='.urlencode($search_user);
|
||||
}
|
||||
if ($search_sale > 0) {
|
||||
$param .= '&search_sale='.urlencode($search_sale);
|
||||
}
|
||||
if ($search_total_ht != '') {
|
||||
$param .= '&search_total_ht='.urlencode($search_total_ht);
|
||||
}
|
||||
if ($search_total_vat != '') {
|
||||
$param .= '&search_total_vat='.urlencode($search_total_vat);
|
||||
}
|
||||
if ($search_total_ttc != '') {
|
||||
$param .= '&search_total_ttc='.urlencode($search_total_ttc);
|
||||
}
|
||||
if ($search_project_ref >= 0) {
|
||||
$param .= "&search_project_ref=".urlencode($search_project_ref);
|
||||
}
|
||||
if ($show_files) {
|
||||
$param .= '&show_files='.urlencode($show_files);
|
||||
}
|
||||
if ($optioncss != '') {
|
||||
$param .= '&optioncss='.urlencode($optioncss);
|
||||
}
|
||||
if ($billed != '') {
|
||||
$param .= '&billed='.urlencode($billed);
|
||||
}
|
||||
|
||||
header("Location: ".$_SERVER['PHP_SELF'].'?'.$param);
|
||||
exit;
|
||||
} else {
|
||||
$db->rollback();
|
||||
|
||||
$action = 'create';
|
||||
$_GET["origin"] = $_POST["origin"];
|
||||
$_GET["originid"] = $_POST["originid"];
|
||||
if (!empty($errors)) {
|
||||
setEventMessages(null, $errors, 'errors');
|
||||
} else {
|
||||
setEventMessages("Error", null, 'errors');
|
||||
}
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($action == 'validate' && $permissiontoadd) {
|
||||
if (GETPOST('confirm') == 'yes') {
|
||||
|
||||
@ -163,7 +163,7 @@ $arrayfields = dol_sort_array($arrayfields, 'position');
|
||||
if (GETPOST('cancel', 'alpha')) {
|
||||
$action = 'list'; $massaction = '';
|
||||
}
|
||||
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createbills') {
|
||||
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
|
||||
$massaction = '';
|
||||
}
|
||||
|
||||
|
||||
@ -646,349 +646,6 @@ if (!$error && $massaction == 'confirm_presend') {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Move this action into commande/list.php if called only by this page.
|
||||
if ($massaction == 'confirm_createbills') { // Create bills from orders.
|
||||
$orders = GETPOST('toselect', 'array');
|
||||
$createbills_onebythird = GETPOST('createbills_onebythird', 'int');
|
||||
$validate_invoices = GETPOST('validate_invoices', 'int');
|
||||
|
||||
$errors = array();
|
||||
|
||||
$TFact = array();
|
||||
$TFactThird = array();
|
||||
$TFactThirdNbLines = array();
|
||||
|
||||
$nb_bills_created = 0;
|
||||
$lastid= 0;
|
||||
$lastref = '';
|
||||
|
||||
$db->begin();
|
||||
|
||||
foreach ($orders as $id_order) {
|
||||
$cmd = new Commande($db);
|
||||
if ($cmd->fetch($id_order) <= 0) {
|
||||
continue;
|
||||
}
|
||||
$cmd->fetch_thirdparty();
|
||||
|
||||
$objecttmp = new Facture($db);
|
||||
if (!empty($createbills_onebythird) && !empty($TFactThird[$cmd->socid])) {
|
||||
// If option "one bill per third" is set, and an invoice for this thirdparty was already created, we re-use it.
|
||||
$objecttmp = $TFactThird[$cmd->socid];
|
||||
} else {
|
||||
// If we want one invoice per order or if there is no first invoice yet for this thirdparty.
|
||||
$objecttmp->socid = $cmd->socid;
|
||||
$objecttmp->thirdparty = $cmd->thirdparty;
|
||||
|
||||
$objecttmp->type = $objecttmp::TYPE_STANDARD;
|
||||
$objecttmp->cond_reglement_id = !empty($cmd->cond_reglement_id) ? $cmd->cond_reglement_id : $cmd->thirdparty->cond_reglement_id;
|
||||
$objecttmp->mode_reglement_id = !empty($cmd->mode_reglement_id) ? $cmd->mode_reglement_id : $cmd->thirdparty->mode_reglement_id;
|
||||
|
||||
$objecttmp->fk_project = $cmd->fk_project;
|
||||
$objecttmp->multicurrency_code = $cmd->multicurrency_code;
|
||||
if (empty($createbills_onebythird)) {
|
||||
$objecttmp->ref_client = $cmd->ref_client;
|
||||
}
|
||||
|
||||
$datefacture = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
|
||||
if (empty($datefacture)) {
|
||||
$datefacture = dol_now();
|
||||
}
|
||||
|
||||
$objecttmp->date = $datefacture;
|
||||
$objecttmp->origin = 'commande';
|
||||
$objecttmp->origin_id = $id_order;
|
||||
|
||||
$objecttmp->array_options = $cmd->array_options; // Copy extrafields
|
||||
|
||||
$res = $objecttmp->create($user);
|
||||
|
||||
if ($res > 0) {
|
||||
$nb_bills_created++;
|
||||
$lastref = $objecttmp->ref;
|
||||
$lastid = $objecttmp->id;
|
||||
|
||||
$TFactThird[$cmd->socid] = $objecttmp;
|
||||
$TFactThirdNbLines[$cmd->socid] = 0; //init nblines to have lines ordered by expedition and rang
|
||||
} else {
|
||||
$langs->load("errors");
|
||||
$errors[] = $cmd->ref.' : '.$langs->trans($objecttmp->error);
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($objecttmp->id > 0) {
|
||||
$res = $objecttmp->add_object_linked($objecttmp->origin, $id_order);
|
||||
|
||||
if ($res == 0) {
|
||||
$errors[] = $objecttmp->error;
|
||||
$error++;
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
$lines = $cmd->lines;
|
||||
if (empty($lines) && method_exists($cmd, 'fetch_lines')) {
|
||||
$cmd->fetch_lines();
|
||||
$lines = $cmd->lines;
|
||||
}
|
||||
|
||||
$fk_parent_line = 0;
|
||||
$num = count($lines);
|
||||
|
||||
for ($i = 0; $i < $num; $i++) {
|
||||
$desc = ($lines[$i]->desc ? $lines[$i]->desc : '');
|
||||
// If we build one invoice for several orders, we must put the ref of order on the invoice line
|
||||
if (!empty($createbills_onebythird)) {
|
||||
$desc = dol_concatdesc($desc, $langs->trans("Order").' '.$cmd->ref.' - '.dol_print_date($cmd->date, 'day'));
|
||||
}
|
||||
|
||||
if ($lines[$i]->subprice < 0) {
|
||||
// Negative line, we create a discount line
|
||||
$discount = new DiscountAbsolute($db);
|
||||
$discount->fk_soc = $objecttmp->socid;
|
||||
$discount->amount_ht = abs($lines[$i]->total_ht);
|
||||
$discount->amount_tva = abs($lines[$i]->total_tva);
|
||||
$discount->amount_ttc = abs($lines[$i]->total_ttc);
|
||||
$discount->tva_tx = $lines[$i]->tva_tx;
|
||||
$discount->fk_user = $user->id;
|
||||
$discount->description = $desc;
|
||||
$discountid = $discount->create($user);
|
||||
if ($discountid > 0) {
|
||||
$result = $objecttmp->insert_discount($discountid);
|
||||
//$result=$discount->link_to_invoice($lineid,$id);
|
||||
} else {
|
||||
setEventMessages($discount->error, $discount->errors, 'errors');
|
||||
$error++;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// Positive line
|
||||
$product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
|
||||
// Date start
|
||||
$date_start = false;
|
||||
if ($lines[$i]->date_debut_prevue) {
|
||||
$date_start = $lines[$i]->date_debut_prevue;
|
||||
}
|
||||
if ($lines[$i]->date_debut_reel) {
|
||||
$date_start = $lines[$i]->date_debut_reel;
|
||||
}
|
||||
if ($lines[$i]->date_start) {
|
||||
$date_start = $lines[$i]->date_start;
|
||||
}
|
||||
//Date end
|
||||
$date_end = false;
|
||||
if ($lines[$i]->date_fin_prevue) {
|
||||
$date_end = $lines[$i]->date_fin_prevue;
|
||||
}
|
||||
if ($lines[$i]->date_fin_reel) {
|
||||
$date_end = $lines[$i]->date_fin_reel;
|
||||
}
|
||||
if ($lines[$i]->date_end) {
|
||||
$date_end = $lines[$i]->date_end;
|
||||
}
|
||||
// Reset fk_parent_line for no child products and special product
|
||||
if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
|
||||
$fk_parent_line = 0;
|
||||
}
|
||||
|
||||
// Extrafields
|
||||
if (method_exists($lines[$i], 'fetch_optionals')) {
|
||||
$lines[$i]->fetch_optionals();
|
||||
$array_options = $lines[$i]->array_options;
|
||||
}
|
||||
|
||||
$objecttmp->context['createfromclone'];
|
||||
|
||||
$rang = $lines[$i]->rang;
|
||||
//there may already be rows from previous orders
|
||||
if (!empty($createbills_onebythird))
|
||||
$rang = $TFactThirdNbLines[$cmd->socid];
|
||||
|
||||
$result = $objecttmp->addline(
|
||||
$desc,
|
||||
$lines[$i]->subprice,
|
||||
$lines[$i]->qty,
|
||||
$lines[$i]->tva_tx,
|
||||
$lines[$i]->localtax1_tx,
|
||||
$lines[$i]->localtax2_tx,
|
||||
$lines[$i]->fk_product,
|
||||
$lines[$i]->remise_percent,
|
||||
$date_start,
|
||||
$date_end,
|
||||
0,
|
||||
$lines[$i]->info_bits,
|
||||
$lines[$i]->fk_remise_except,
|
||||
'HT',
|
||||
0,
|
||||
$product_type,
|
||||
$rang,
|
||||
$lines[$i]->special_code,
|
||||
$objecttmp->origin,
|
||||
$lines[$i]->rowid,
|
||||
$fk_parent_line,
|
||||
$lines[$i]->fk_fournprice,
|
||||
$lines[$i]->pa_ht,
|
||||
$lines[$i]->label,
|
||||
$array_options,
|
||||
100,
|
||||
0,
|
||||
$lines[$i]->fk_unit
|
||||
);
|
||||
if ($result > 0) {
|
||||
$lineid = $result;
|
||||
if (!empty($createbills_onebythird)) //increment rang to keep order
|
||||
$TFactThirdNbLines[$rcp->socid]++;
|
||||
} else {
|
||||
$lineid = 0;
|
||||
$error++;
|
||||
break;
|
||||
}
|
||||
// Defined the new fk_parent_line
|
||||
if ($result > 0 && $lines[$i]->product_type == 9) {
|
||||
$fk_parent_line = $result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//$cmd->classifyBilled($user); // Disabled. This behavior must be set or not using the workflow module.
|
||||
|
||||
if (!empty($createbills_onebythird) && empty($TFactThird[$cmd->socid])) {
|
||||
$TFactThird[$cmd->socid] = $objecttmp;
|
||||
} else {
|
||||
$TFact[$objecttmp->id] = $objecttmp;
|
||||
}
|
||||
}
|
||||
|
||||
// Build doc with all invoices
|
||||
$TAllFact = empty($createbills_onebythird) ? $TFact : $TFactThird;
|
||||
$toselect = array();
|
||||
|
||||
if (!$error && $validate_invoices) {
|
||||
$massaction = $action = 'builddoc';
|
||||
|
||||
foreach ($TAllFact as &$objecttmp) {
|
||||
$result = $objecttmp->validate($user);
|
||||
if ($result <= 0) {
|
||||
$error++;
|
||||
setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
|
||||
break;
|
||||
}
|
||||
|
||||
$id = $objecttmp->id; // For builddoc action
|
||||
|
||||
// Builddoc
|
||||
$donotredirect = 1;
|
||||
$upload_dir = $conf->facture->dir_output;
|
||||
$permissiontoadd = $user->rights->facture->creer;
|
||||
|
||||
// Call action to build doc
|
||||
$savobject = $object;
|
||||
$object = $objecttmp;
|
||||
include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
|
||||
$object = $savobject;
|
||||
}
|
||||
|
||||
$massaction = $action = 'confirm_createbills';
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
$db->commit();
|
||||
|
||||
if ($nb_bills_created == 1) {
|
||||
$texttoshow = $langs->trans('BillXCreated', '{s1}');
|
||||
$texttoshow = str_replace('{s1}', '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?id='.urlencode($lastid).'">'.$lastref.'</a>', $texttoshow);
|
||||
setEventMessages($texttoshow, null, 'mesgs');
|
||||
} else {
|
||||
setEventMessages($langs->trans('BillCreated', $nb_bills_created), null, 'mesgs');
|
||||
}
|
||||
|
||||
// Make a redirect to avoid to bill twice if we make a refresh or back
|
||||
$param = '';
|
||||
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
|
||||
$param .= '&contextpage='.urlencode($contextpage);
|
||||
}
|
||||
if ($limit > 0 && $limit != $conf->liste_limit) {
|
||||
$param .= '&limit='.urlencode($limit);
|
||||
}
|
||||
if ($sall) {
|
||||
$param .= '&sall='.urlencode($sall);
|
||||
}
|
||||
if ($socid > 0) {
|
||||
$param .= '&socid='.urlencode($socid);
|
||||
}
|
||||
if ($search_status != '') {
|
||||
$param .= '&search_status='.urlencode($search_status);
|
||||
}
|
||||
if ($search_orderday) {
|
||||
$param .= '&search_orderday='.urlencode($search_orderday);
|
||||
}
|
||||
if ($search_ordermonth) {
|
||||
$param .= '&search_ordermonth='.urlencode($search_ordermonth);
|
||||
}
|
||||
if ($search_orderyear) {
|
||||
$param .= '&search_orderyear='.urlencode($search_orderyear);
|
||||
}
|
||||
if ($search_deliveryday) {
|
||||
$param .= '&search_deliveryday='.urlencode($search_deliveryday);
|
||||
}
|
||||
if ($search_deliverymonth) {
|
||||
$param .= '&search_deliverymonth='.urlencode($search_deliverymonth);
|
||||
}
|
||||
if ($search_deliveryyear) {
|
||||
$param .= '&search_deliveryyear='.urlencode($search_deliveryyear);
|
||||
}
|
||||
if ($search_ref) {
|
||||
$param .= '&search_ref='.urlencode($search_ref);
|
||||
}
|
||||
if ($search_company) {
|
||||
$param .= '&search_company='.urlencode($search_company);
|
||||
}
|
||||
if ($search_ref_customer) {
|
||||
$param .= '&search_ref_customer='.urlencode($search_ref_customer);
|
||||
}
|
||||
if ($search_user > 0) {
|
||||
$param .= '&search_user='.urlencode($search_user);
|
||||
}
|
||||
if ($search_sale > 0) {
|
||||
$param .= '&search_sale='.urlencode($search_sale);
|
||||
}
|
||||
if ($search_total_ht != '') {
|
||||
$param .= '&search_total_ht='.urlencode($search_total_ht);
|
||||
}
|
||||
if ($search_total_vat != '') {
|
||||
$param .= '&search_total_vat='.urlencode($search_total_vat);
|
||||
}
|
||||
if ($search_total_ttc != '') {
|
||||
$param .= '&search_total_ttc='.urlencode($search_total_ttc);
|
||||
}
|
||||
if ($search_project_ref >= 0) {
|
||||
$param .= "&search_project_ref=".urlencode($search_project_ref);
|
||||
}
|
||||
if ($show_files) {
|
||||
$param .= '&show_files='.urlencode($show_files);
|
||||
}
|
||||
if ($optioncss != '') {
|
||||
$param .= '&optioncss='.urlencode($optioncss);
|
||||
}
|
||||
if ($billed != '') {
|
||||
$param .= '&billed='.urlencode($billed);
|
||||
}
|
||||
|
||||
header("Location: ".$_SERVER['PHP_SELF'].'?'.$param);
|
||||
exit;
|
||||
} else {
|
||||
$db->rollback();
|
||||
|
||||
$action = 'create';
|
||||
$_GET["origin"] = $_POST["origin"];
|
||||
$_GET["originid"] = $_POST["originid"];
|
||||
setEventMessages("Error", null, 'errors');
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error && $massaction == 'cancelorders') {
|
||||
$db->begin();
|
||||
|
||||
|
||||
@ -149,7 +149,7 @@ $arrayfields = dol_sort_array($arrayfields, 'position');
|
||||
if (GETPOST('cancel', 'alpha')) {
|
||||
$action = 'list'; $massaction = '';
|
||||
}
|
||||
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createbills') {
|
||||
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
|
||||
$massaction = '';
|
||||
}
|
||||
|
||||
|
||||
@ -228,7 +228,7 @@ if ((empty($user->rights->fournisseur->facture->lire) && empty($conf->global->MA
|
||||
if (GETPOST('cancel', 'alpha')) {
|
||||
$action = 'list'; $massaction = '';
|
||||
}
|
||||
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createbills') {
|
||||
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
|
||||
$massaction = '';
|
||||
}
|
||||
|
||||
@ -829,7 +829,7 @@ if ($resql) {
|
||||
//'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
|
||||
//'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
|
||||
);
|
||||
//if($user->rights->fournisseur->facture->creer) $arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisCustomer");
|
||||
|
||||
if (!empty($conf->paymentbybanktransfer->enabled) && !empty($user->rights->paymentbybanktransfer->create)) {
|
||||
$langs->load('withdrawals');
|
||||
$arrayofmassactions['banktransfertrequest'] = img_picto('', 'payment', 'class="pictofixedwidth"').$langs->trans("MakeBankTransferOrder");
|
||||
@ -837,7 +837,7 @@ if ($resql) {
|
||||
if ($user->rights->fournisseur->facture->supprimer) {
|
||||
$arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
|
||||
}
|
||||
if (in_array($massaction, array('presend', 'predelete', 'createbills'))) {
|
||||
if (in_array($massaction, array('presend', 'predelete'))) {
|
||||
$arrayofmassactions = array();
|
||||
}
|
||||
$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
|
||||
@ -868,45 +868,6 @@ if ($resql) {
|
||||
$trackid = 'sinv'.$object->id;
|
||||
include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
|
||||
|
||||
if ($massaction == 'createbills') {
|
||||
//var_dump($_REQUEST);
|
||||
print '<input type="hidden" name="massaction" value="confirm_createbills">';
|
||||
|
||||
print '<table class="border" width="100%" >';
|
||||
print '<tr>';
|
||||
print '<td class="titlefieldmiddle">';
|
||||
print $langs->trans('DateInvoice');
|
||||
print '</td>';
|
||||
print '<td>';
|
||||
print $form->selectDate('', '', '', '', '', '', 1, 1);
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
print '<tr>';
|
||||
print '<td>';
|
||||
print $langs->trans('CreateOneBillByThird');
|
||||
print '</td>';
|
||||
print '<td>';
|
||||
print $form->selectyesno('createbills_onebythird', '', 1);
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
print '<tr>';
|
||||
print '<td>';
|
||||
print $langs->trans('ValidateInvoices');
|
||||
print '</td>';
|
||||
print '<td>';
|
||||
print $form->selectyesno('validate_invoices', 1, 1);
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
print '</table>';
|
||||
|
||||
print '<br>';
|
||||
print '<div class="center">';
|
||||
print '<input type="submit" class="button" id="createbills" name="createbills" value="'.$langs->trans('CreateInvoiceForThisCustomer').'"> ';
|
||||
print '<input type="submit" class="button button-cancel" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
|
||||
print '</div>';
|
||||
print '<br>';
|
||||
}
|
||||
|
||||
if ($search_all) {
|
||||
foreach ($fieldstosearchall as $key => $val) {
|
||||
$fieldstosearchall[$key] = $langs->trans($val);
|
||||
|
||||
@ -226,7 +226,7 @@ $arrayfields = dol_sort_array($arrayfields, 'position');
|
||||
if (GETPOST('cancel', 'alpha')) {
|
||||
$action = 'list'; $massaction = '';
|
||||
}
|
||||
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createbills') {
|
||||
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
|
||||
$massaction = '';
|
||||
}
|
||||
|
||||
|
||||
@ -185,7 +185,7 @@ if (GETPOST('cancel', 'alpha')) {
|
||||
$action = 'list';
|
||||
$massaction = '';
|
||||
}
|
||||
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createbills') {
|
||||
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
|
||||
$massaction = '';
|
||||
}
|
||||
|
||||
|
||||
@ -1149,8 +1149,6 @@ if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0 || $allprojectforuser
|
||||
|
||||
// Form to convert time spent into invoice
|
||||
if ($massaction == 'generateinvoice') {
|
||||
print '<input type="hidden" name="massaction" value="confirm_createbills">';
|
||||
|
||||
if ($projectstatic->thirdparty->id > 0) {
|
||||
print '<table class="noborder centerpercent">';
|
||||
print '<tr>';
|
||||
|
||||
@ -166,6 +166,15 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x'
|
||||
}
|
||||
|
||||
if (empty($reshook)) {
|
||||
// Mass actions
|
||||
$objectclass = 'Reception';
|
||||
$objectlabel = 'Receptions';
|
||||
$permissiontoread = $user->rights->reception->lire;
|
||||
$permissiontoadd = $user->rights->reception->creer;
|
||||
$permissiontodelete = $user->rights->reception->supprimer;
|
||||
$uploaddir = $conf->reception->multidir_output[$conf->entity];
|
||||
include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
|
||||
|
||||
if ($massaction == 'confirm_createbills') {
|
||||
$receptions = GETPOST('toselect', 'array');
|
||||
$createbills_onebythird = GETPOST('createbills_onebythird', 'int');
|
||||
|
||||
@ -92,7 +92,7 @@ if (!$user->rights->user->user->lire && !$user->admin) {
|
||||
if (GETPOST('cancel', 'alpha')) {
|
||||
$action = 'list'; $massaction = '';
|
||||
}
|
||||
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createbills') {
|
||||
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
|
||||
$massaction = '';
|
||||
}
|
||||
|
||||
|
||||
@ -203,7 +203,7 @@ $childids = $user->getAllChildIds(1);
|
||||
if (GETPOST('cancel', 'alpha')) {
|
||||
$action = 'list'; $massaction = '';
|
||||
}
|
||||
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createbills') {
|
||||
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
|
||||
$massaction = '';
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user