if ($result <= 0) { $errmsg = $invoice->error; $errmsgs = $invoice->errors; $error++; } } // Add payment onto invoice if ($option == 'bankviainvoice' && $accountid) { require_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php'; require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/functions.lib.php'; $amounts[$invoice->id] = price2num($cotisation); $paiement = new Paiement($db); $paiement->datepaye = $paymentdate; $paiement->amounts = $amounts; $paiement->paiementid = dol_getIdFromCode($db, $operation, 'c_paiement'); $paiement->num_paiement = $num_chq; $paiement->note = $label; if (!$error) { // Create payment line for invoice $paiement_id = $paiement->create($user); if (!$paiement_id > 0) { $errmsg = $paiement->error; $errmsgs = $paiement->errors; $error++; } } if (!$error) { // Add transaction into bank account $bank_line_id = $paiement->addPaymentToBank($user, 'payment', '(SubscriptionPayment)', $accountid, $emetteur_nom, $emetteur_banque); if (!($bank_line_id > 0)) {
break; case 'ESP': $mode_reglement_id = dol_getIdFromCode($db, 'LIQ', 'c_paiement'); $cond_reglement_id = 0; $note .= $langs->trans("Cash") . "\n"; $note .= $langs->trans("Received") . ' : ' . $obj_facturation->montantEncaisse() . " " . $conf->currency . "\n"; $note .= $langs->trans("Rendu") . ' : ' . $obj_facturation->montantRendu() . " " . $conf->currency . "\n"; $note .= "\n"; $note .= '--------------------------------------' . "\n\n"; break; case 'CB': $mode_reglement_id = dol_getIdFromCode($db, 'CB', 'c_paiement'); $cond_reglement_id = 0; break; case 'CHQ': $mode_reglement_id = dol_getIdFromCode($db, 'CHQ', 'c_paiement'); $cond_reglement_id = 0; break; } if (empty($mode_reglement_id)) { $mode_reglement_id = 0; } // If mode_reglement_id not found if (empty($cond_reglement_id)) { $cond_reglement_id = 0; } // If cond_reglement_id not found $note .= $_POST['txtaNotes']; dol_syslog("obj_facturation->getSetPaymentMode()=" . $obj_facturation->getSetPaymentMode() . " mode_reglement_id=" . $mode_reglement_id . " cond_reglement_id=" . $cond_reglement_id); $error = 0; $db->begin();
<?php echo '<tr><td></td></tr>'; echo '<tr><td></td></tr>'; $terminal = new Cash($db); $terminal->fetch($object->fk_cash); $pay = $object->getSommePaiement(); if ($object->customer_pay > $pay) { $pay = $object->customer_pay; } $diff_payment = $object->total_ttc - $pay; $listofpayments = $object->getListOfPayments(); foreach ($listofpayments as $paym) { if ($paym['type'] != 'LIQ') { echo '<tr><th nowrap="nowrap">' . $terminal->select_Paymentname(dol_getIdFromCode($db, $paym['type'], 'c_paiement')) . '</th><td nowrap="nowrap">' . price($paym['amount'], "", "", "", "", 2) . " " . $langs->trans(currency_name($conf->currency)) . "</td></tr>"; } else { echo '<tr><th nowrap="nowrap">' . $terminal->select_Paymentname(dol_getIdFromCode($db, $paym['type'], 'c_paiement')) . '</th><td nowrap="nowrap">' . price($paym['amount'] - ($diff_payment < 0 ? $diff_payment : 0), "", "", "", "", 2) . " " . $langs->trans(currency_name($conf->currency)) . "</td></tr>"; } } echo '<tr><th nowrap="nowrap">' . ($diff_payment < 0 ? $langs->trans("CustomerRet") : $langs->trans("CustomerDeb")) . '</th><td nowrap="nowrap">' . price(abs($diff_payment), "", "", "", "", 2) . " " . $langs->trans(currency_name($conf->currency)) . "</td></tr>"; ?> </table> <div class="note"><p><?php print $conf->global->POS_PREDEF_MSG; ?> </p></div> <script type="text/javascript"> window.print();
/** * Fill the body of email's message with a facture * * @param int $id * * @return string String with ticket data */ public static function fillMailFactureBody($id) { global $db, $conf, $langs, $mysoc; $langs->Load("rewards@rewards"); $facture = new Facture($db); $res = $facture->fetch($id); $mysoc = new Societe($db); $mysoc->fetch($facture->socid); $userstatic = new User($db); $userstatic->fetch($facture->user_valid); $label = $facture->ref; $message = $conf->global->MAIN_INFO_SOCIETE_NOM . " \n" . $conf->global->MAIN_INFO_SOCIETE_ADRESSE . " \n" . $conf->global->MAIN_INFO_SOCIETE_CP . ' ' . $conf->global->MAIN_INFO_SOCIETE_VILLE . " \n\n"; $message .= $label . " \n" . dol_print_date($facture->date_creation, 'dayhourtext') . " \n"; $message .= $langs->transnoentities("Vendor") . ': ' . $userstatic->fistname . " " . $userstatic->lastname . "\n"; $sql = "SELECT fk_place,fk_cash FROM " . MAIN_DB_PREFIX . "pos_facture WHERE fk_facture =" . $facture->id; $result = $db->query($sql); if ($result) { $objp = $db->fetch_object($result); if ($objp->fk_place > 0) { $place = new Place($db); $place->fetch($objp->fk_place); $message .= $langs->trans("Place") . ': ' . $place->name . "\n"; } } $message .= "\n"; $message .= $langs->transnoentities("Label") . "\t\t\t\t\t\t" . $langs->transnoentities("Qty") . "/" . $langs->transnoentities("Price") . "\t\t" . $langs->transnoentities("Total") . "\n"; //$facture->getLinesArray(); if (!empty($facture->lines)) { $subtotal = 0; foreach ($facture->lines as $line) { $espacio = ''; $totalline = $line->qty * $line->subprice; if (empty($line->libelle)) { $line->libelle = $line->description; } while (dol_strlen(dol_trunc($line->libelle, 30) . $espacio) < 29) { $espacio .= " \t"; } $message .= dol_trunc($line->libelle, 33) . $espacio; $message .= "\t\t" . $line->qty . " * " . price($line->subprice) . "\t\t" . price($line->total_ht) . ' ' . $langs->trans(currency_name($conf->currency)) . "\n"; $subtotal[$line->tva_tx] += $line->total_ht; $subtotaltva[$line->tva_tx] += $line->total_tva; if (!empty($line->total_localtax1)) { $localtax1 = $line->localtax1_tx; } if (!empty($line->total_localtax2)) { $localtax2 = $line->localtax2_tx; } } } else { $message .= $langs->transnoentities("ErrNoArticles") . "\n"; } $message .= $langs->transnoentities("TotalTTC") . ":\t" . price($facture->total_ttc) . " " . $langs->trans(currency_name($conf->currency)) . "\n"; $message .= "\n" . $langs->trans("TotalHT") . "\t" . $langs->trans("VAT") . "\t" . $langs->trans("TotalVAT") . "\n"; if (!empty($subtotal)) { foreach ($subtotal as $totkey => $totval) { if ($tvakey > 0) { $message .= price($subtotal[$totkey], "", "", "", "", 2) . "\t\t\t" . price($totkey, "", "", "", "", 2) . "%\t" . price($subtotaltva[$totkey], "", "", "", "", 2) . "\n"; } } } $message .= "-------------------------------\n"; $message .= price($facture->total_ht, "", "", "", "", 2) . "\t\t\t----\t" . price($facture->total_tva, "", "", "", "", 2) . "\n"; if ($facture->total_localtax1 != 0) { $message .= $langs->transcountrynoentities("TotalLT1", $mysoc->country_code) . " " . price($localtax1, "", "", "", "", 2) . "%\t" . price($facture->total_localtax1, "", "", "", "", 2) . " " . $langs->trans(currency_name($conf->currency)) . "\n"; } if ($facture->total_localtax2 != 0) { $message .= $langs->transcountrynoentities("TotalLT2", $mysoc->country_code) . " " . price($localtax2, "", "", "", "", 2) . "%\t" . price($facture->total_localtax2, "", "", "", "", 2) . " " . $langs->trans(currency_name($conf->currency)) . "\n"; } $message .= "\n\n"; $terminal = new Cash($db); $sql = 'SELECT fk_cash, customer_pay FROM ' . MAIN_DB_PREFIX . 'pos_facture WHERE fk_facture = ' . $facture->id; $resql = $db->query($sql); $obj = $db->fetch_object($resql); $customer_pay = $obj->customer_pay; $terminal->fetch($obj > fk_cash); if (!empty($conf->rewards->enabled)) { $rewards = new Rewards($db); $points = $rewards->getInvoicePoints($facture->id); } if ($facture->type == 0) { $pay = $facture->getSommePaiement(); if (!empty($conf->rewards->enabled)) { $usepoints = abs($rewards->getInvoicePoints($facture->id, 1)); $moneypoints = abs($usepoints * $conf->global->REWARDS_DISCOUNT); //falta fer algo per aci if ($customer_pay > $pay - $moneypoints) { $pay = $customer_pay; } else { $pay = $pay - $moneypoints; } } else { if ($customer_pay > $pay) { $pay = $customer_pay; } } } if ($facture->type == 2) { $customer_pay = $customer_pay * -1; $pay = $facture->getSommePaiement(); if (!empty($conf->rewards->enabled)) { $usepoints = abs($rewards->getInvoicePoints($facture->id, 1)); $moneypoints = abs($usepoints * $conf->global->REWARDS_DISCOUNT); //falta fer algo per aci if ($customer_pay > $pay - $moneypoints) { $pay = $customer_pay; } else { $pay = $pay - $moneypoints; } } else { if ($customer_pay > $pay) { $pay = $customer_pay; } } } $diff_payment = $facture->total_ttc - $moneypoints - $pay; $listofpayments = $facture->getListOfPayments(); foreach ($listofpayments as $paym) { if ($paym['type'] != 'PNT') { if ($paym['type'] != 'LIQ') { $message .= $terminal->select_Paymentname(dol_getIdFromCode($db, $paym['type'], 'c_paiement')) . "\t" . price($paym['amount'], "", "", "", "", 2) . " " . $langs->trans(currency_name($conf->currency)) . "\n"; } else { $message .= $terminal->select_Paymentname(dol_getIdFromCode($db, $paym['type'], 'c_paiement')) . "\t" . price($paym['amount'] - ($diff_payment < 0 ? $diff_payment : 0), "", "", "", "", 2) . " " . $langs->trans(currency_name($conf->currency)) . "\n"; } } } if (!empty($conf->rewards->enabled)) { if ($moneypoints > 0) { $message .= $usepoints . " " . $langs->trans("Points") . "\t" . price($moneypoints, "", "", "", "", 2) . " " . $langs->trans(currency_name($conf->currency)) . "\n"; } } $message .= ($diff_payment < 0 ? $langs->trans("CustomerRet") : $langs->trans("CustomerDeb")) . "\t" . price(abs($diff_payment), "", "", "", "", 2) . " " . $langs->trans(currency_name($conf->currency)) . "\n"; if ($points != 0 && !empty($conf->rewards->enabled)) { $message .= $langs->trans("TotalPointsInvoice") . "\t" . price($points, "", "", "", "", 2) . " " . $langs->trans('Points') . "\n"; $total_points = $rewards->getCustomerPoints($facture->socid); $message .= $langs->trans("DispoPoints") . "\t" . price($total_points, "", "", "", "", 2) . " " . $langs->trans('Points') . "\n"; } $message .= $conf->global->POS_PREDEF_MSG; return $message; }
print ' '; print '<input type="submit" class="button" name="cancel" value="' . $langs->trans("Cancel") . '">'; print '</div>'; print "</form>"; } // View or edit if ($id > 0) { $result1 = $object->fetch($id); $result2 = $object->fetch_thirdparty(); $result3 = $object->fetch_contact(); $result4 = $object->fetch_userassigned(); $result5 = $object->fetch_optionals($id, $extralabels); if ($listUserAssignedUpdated || $donotclearsession) { $datep = dol_mktime($fulldayevent ? '00' : $aphour, $fulldayevent ? '00' : $apmin, 0, $_POST["apmonth"], $_POST["apday"], $_POST["apyear"]); $datef = dol_mktime($fulldayevent ? '23' : $p2hour, $fulldayevent ? '59' : $p2min, $fulldayevent ? '59' : '0', $_POST["p2month"], $_POST["p2day"], $_POST["p2year"]); $object->fk_action = dol_getIdFromCode($db, GETPOST("actioncode"), 'c_actioncomm'); $object->label = GETPOST("label"); $object->datep = $datep; $object->datef = $datef; $object->percentage = $percentage; $object->priority = GETPOST("priority"); $object->fulldayevent = GETPOST("fullday") ? 1 : 0; $object->location = GETPOST('location'); $object->socid = GETPOST("socid"); $object->contactid = GETPOST("contactid", 'int'); //$object->societe->id = $_POST["socid"]; // deprecated //$object->contact->id = $_POST["contactid"]; // deprecated $object->fk_project = GETPOST("projectid", 'int'); $object->note = GETPOST("note"); } if ($result1 < 0 || $result2 < 0 || $result3 < 0 || $result4 < 0 || $result5 < 0) {
function _setPayment($user, $db, $conf, $langs) { $TPayment = GETPOST('payment', 'array'); $fk_bank = GETPOST('fk_bank', 'int'); if (empty($fk_bank)) { if (function_exists('setEventMessages')) { setEventMessages($langs->transnoentitiesnoconv('ErrorPaymentImportNoBankSelected'), array(), 'errors'); } else { setEventMessage($langs->transnoentitiesnoconv('ErrorPaymentImportNoBankSelected'), 'errors'); } return; } $mode_reglement = GETPOST('paiementcode', 'alpha'); $TFactureNotFound = $TPaimentError = $TWriteBankFail = array(); $nb_facture_not_found = $nb_payment = $nb_writebank = 0; foreach ($TPayment as $TInfoPayment) { $facture_ref = trim($TInfoPayment['facture_ref']); $rib = trim($TInfoPayment['rib']); $amount = price2num($TInfoPayment['amount']); $date_creation = trim($TInfoPayment['date_creation']); $num_payment = trim($TInfoPayment['num_payment']); $note = trim($TInfoPayment['note']); if ($amount <= 0) { continue; } $facture = new Facture($db); if ($facture->fetch(null, $facture_ref) > 0) { if ($facture->paye) { $TFactureAlreadyPaid[] = $langs->transnoentitiesnoconv('paymentimport_warningFactureAlreadyPaid', $facture_ref); continue; // Sécurité si jamais la facture est déjà payé on ne saisie pas de nouveau règlement } if (!empty($conf->global->PAYMENTIMPORT_FORCE_DATE_TODAY)) { $datepaye = dol_mktime(date('H'), date('m'), date('s'), date('m'), date('d'), date('Y')); } else { $date_creation = explode('/', $date_creation); $datepaye = dol_mktime(12, 0, 0, $date_creation[1], $date_creation[0], $date_creation[2]); } if (empty($mode_reglement)) { $paiementcode = $facture->mode_reglement_code; } else { $paiementcode = $mode_reglement; } // Creation of payment line $paiement = new Paiement($db); $paiement->datepaye = $datepaye; $paiement->amounts = array($facture->id => $amount); // Array with all payments dispatching $paiement->paiementid = dol_getIdFromCode($db, $paiementcode, 'c_paiement'); $paiement->num_paiement = $num_payment; $paiement->note = $note; $paiement_id = $paiement->create($user, 1); if ($paiement_id > 0) { $nb_payment++; $label = '(CustomerInvoicePayment)'; $result = $paiement->addPaymentToBank($user, 'payment', $label, $fk_bank, '', ''); if ($result > 0) { $nb_writebank++; } else { $TWriteBankFail[] = $langs->transnoentitiesnoconv('paymentimport_errorwritebank', $facture_ref); } } else { $TPaimentError[] = $langs->transnoentitiesnoconv('paymentimport_errorpayment', $facture_ref, $rib, $amount); } } else { $TFactureNotFound[] = $langs->transnoentitiesnoconv('paymentimport_errorfactnotfound', $facture_ref); $nb_facture_not_found++; } } if ($nb_facture_not_found > 0) { if (function_exists('setEventMessages')) { setEventMessages($langs->trans('paymentimport_nb_facture_not_found', $nb_facture_not_found), array(), 'errors'); } else { setEventMessage($langs->trans('paymentimport_nb_facture_not_found', $nb_facture_not_found), 'errors'); } } if ($nb_payment > 0) { if (function_exists('setEventMessages')) { setEventMessages($langs->trans('paymentimport_nb_payment', $nb_payment), array()); } else { setEventMessage($langs->trans('paymentimport_nb_payment', $nb_payment)); } } if ($nb_writebank > 0) { if (function_exists('setEventMessages')) { setEventMessages($langs->trans('paymentimport_nb_writebank', $nb_writebank), array()); } else { setEventMessage($langs->trans('paymentimport_nb_writebank', $nb_writebank)); } } $_SESSION['TFactureNotFound'] = $TFactureNotFound; $_SESSION['TPaimentError'] = $TPaimentError; $_SESSION['TWriteBankFail'] = $TWriteBankFail; $_SESSION['TFactureAlreadyPaid'] = $TFactureAlreadyPaid; }
} $terminal = new Cash($db); $terminal->fetch($ticket->fk_cash); $pay = $ticket->getSommePaiement(); if ($ticket->customer_pay > $pay) { $pay = $ticket->customer_pay; } $diff_payment = $ticket->total_ttc - $pay; $listofpayments = $ticket->getListOfPayments(); $pays = array(); if (!empty($listofpayments)) { foreach ($listofpayments as $paym) { if ($paym['type'] != 'LIQ') { $paytext = $terminal->select_Paymentname(dol_getIdFromCode($db, $paym['type'], 'c_paiement')) . " " . price($paym['amount'], "", "", "", "", 2) . " " . $langs->trans(currency_name($conf->currency)); } else { $paytext = $terminal->select_Paymentname(dol_getIdFromCode($db, $paym['type'], 'c_paiement')) . " " . price($paym['amount'] - ($diff_payment < 0 ? $diff_payment : 0), "", "", "", "", 2) . " " . $langs->trans(currency_name($conf->currency)); } $pays[] = $paytext; } } else { $paytext = ""; $pays[] = $paytext; } $json_data['pays_lines'] = $pays; $json_data['customer_ret'] = ($diff_payment < 0 ? $langs->trans("CustomerRet") : $langs->trans("CustomerDeb")) . " " . price(abs($diff_payment), "", "", "", "", 2) . " " . $langs->trans(currency_name($conf->currency)); $json_data['predef_msg'] = $conf->global->POS_PREDEF_MSG; } if ($pending_print[0][0] == "C") { $json_data = array(); $sql = "select fk_user, date_c, fk_cash, ref"; $sql .= " from " . MAIN_DB_PREFIX . "pos_control_cash";
} print '</td></tr>'; // Statut print '<tr><td>' . $langs->trans("Status") . '</td><td>' . $object->getLibStatut(4) . '</td></tr>'; // Date start print '<tr><td>' . $langs->trans("DateStart") . '</td><td>'; print dol_print_date($object->date_start, 'day'); print '</td></tr>'; // Date end print '<tr><td>' . $langs->trans("DateEnd") . '</td><td>'; print dol_print_date($object->date_end, 'day'); print '</td></tr>'; if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) { // Opportunity status print '<tr><td>' . $langs->trans("OpportunityStatus") . '</td><td>'; $code = dol_getIdFromCode($db, $object->opp_status, 'c_lead_status', 'rowid', 'code'); if ($code) { print $langs->trans("OppStatus" . $code); } print '</td></tr>'; // Opportunity Amount print '<tr><td>' . $langs->trans("OpportunityAmount") . '</td><td>'; if (strcmp($object->opp_amount, '')) { print price($object->opp_amount, '', $langs, 0, 0, 0, $conf->currency); } print '</td></tr>'; } // Budget print '<tr><td>' . $langs->trans("Budget") . '</td><td>'; if (strcmp($object->budget_amount, '')) { print price($object->budget_amount, '', $langs, 0, 0, 0, $conf->currency);
$("#actioncode").change(function() { if ($("#actioncode").val() == \'AC_RDV\') $("#dateend").addClass("fieldrequired"); else $("#dateend").removeClass("fieldrequired"); }); })'; print '</script>' . "\n"; } print '<form name="formaction" 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="donotclearsession" value="1">'; if ($backtopage) { print '<input type="hidden" name="backtopage" value="' . ($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"]) . '">'; } if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) { print '<input type="hidden" name="actioncode" value="' . dol_getIdFromCode($db, 'AC_OTH', 'c_actioncomm') . '">'; } if (GETPOST("actioncode") == 'AC_RDV') { print_fiche_titre($langs->trans("AddActionRendezVous")); } else { print_fiche_titre($langs->trans("AddAnAction")); } dol_fiche_head(); print '<table class="border" width="100%">'; // Type of event if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) { print '<tr><td width="30%"><span class="fieldrequired">' . $langs->trans("Type") . '</span></b></td><td>'; $formactions->select_type_actions(GETPOST("actioncode") ? GETPOST("actioncode") : $object->type_code, "actioncode", "systemauto"); print '</td></tr>'; } // Title
if ($aphour == -1) { $aphour = '0'; } if ($apmin == -1) { $apmin = '0'; } if ($p2hour == -1) { $p2hour = '0'; } if ($p2min == -1) { $p2min = '0'; } $object->fetch($id); $datep = dol_mktime($fulldayevent ? '00' : $aphour, $fulldayevent ? '00' : $apmin, 0, $_POST["apmonth"], $_POST["apday"], $_POST["apyear"]); $datef = dol_mktime($fulldayevent ? '23' : $p2hour, $fulldayevent ? '59' : $p2min, $fulldayevent ? '59' : '0', $_POST["p2month"], $_POST["p2day"], $_POST["p2year"]); $object->fk_action = dol_getIdFromCode($db, $_POST["actioncode"], 'c_actioncomm'); $object->label = $_POST["label"]; $object->datep = $datep; $object->datef = $datef; $object->percentage = $percentage; $object->priority = $_POST["priority"]; $object->fulldayevent = $_POST["fullday"] ? 1 : 0; $object->location = GETPOST('location'); $object->societe->id = $_POST["socid"]; $object->contact->id = $_POST["contactid"]; $object->fk_project = $_POST["projectid"]; $object->note = $_POST["note"]; $object->pnote = $_POST["note"]; $object->fk_element = $_POST["fk_element"]; $object->elementtype = $_POST["elementtype"]; if (!$datef && $percentage == 100) {
/** * Check return management * Reopen linked invoices and create a new negative payment. * * @param int $bank_id Id of bank transaction line concerned * @param date $rejection_date Date to use on the negative payment * @return int Id of negative payment line created */ function rejectCheck($bank_id, $rejection_date) { global $db, $user; $payment = new Paiement($db); $payment->fetch(0, 0, $bank_id); $bankline = new AccountLine($db); $bankline->fetch($bank_id); /* Conciliation is allowed because when check is returned, a new line is created onto bank transaction log. if ($bankline->rappro) { $this->error='ActionRefusedLineAlreadyConciliated'; return -1; }*/ $this->db->begin(); // Not conciliated, we can delete it //$bankline->delete($user); // We delete $bankaccount = $payment->fk_account; // Get invoices list to reopen them $sql = 'SELECT pf.fk_facture, pf.amount'; $sql .= ' FROM ' . MAIN_DB_PREFIX . 'paiement_facture as pf'; $sql .= ' WHERE pf.fk_paiement = ' . $payment->id; $resql = $db->query($sql); if ($resql) { $rejectedPayment = new Paiement($db); $rejectedPayment->amounts = array(); $rejectedPayment->datepaye = $rejection_date; $rejectedPayment->paiementid = dol_getIdFromCode($this->db, 'CHQ', 'c_paiement'); $rejectedPayment->num_paiement = $payment->numero; while ($obj = $db->fetch_object($resql)) { $invoice = new Facture($db); $invoice->fetch($obj->fk_facture); $invoice->set_unpaid($user); $rejectedPayment->amounts[$obj->fk_facture] = price2num($obj->amount) * -1; } $result = $rejectedPayment->create($user); if ($result > 0) { // We created a negative payment, we also add the line as bank transaction $result = $rejectedPayment->addPaymentToBank($user, 'payment', '(CheckRejected)', $bankaccount, '', ''); if ($result > 0) { $result = $payment->reject(); if ($result > 0) { $this->db->commit(); return $rejectedPayment->id; } else { $this->db->rollback(); return -1; } } else { $this->error = $rejectedPayment->error; $this->errors = $rejectedPayment->errors; $this->db->rollback(); return -1; } } else { $this->error = $rejectedPayment->error; $this->errors = $rejectedPayment->errors; $this->db->rollback(); return -1; } } else { $this->error = $this->db->lasterror(); $this->db->rollback(); return -1; } }
<?php echo '<tr><td></td></tr>'; echo '<tr><td></td></tr>'; $terminal = new Cash($db); $terminal->fetch($object->fk_cash); $pay = $object->getSommePaiement(); if ($object->customer_pay > $pay) { $pay = $object->customer_pay; } $diff_payment = $object->total_ttc - $pay; $listofpayments = $object->getListOfPayments(); foreach ($listofpayments as $paym) { if ($paym['type'] != 'LIQ') { echo '<tr><th nowrap="nowrap">' . $terminal->select_Paymentname(dol_getIdFromCode($db, $paym['type'], 'c_paiement')) . '</th><td nowrap="nowrap">' . price($paym['amount'], "", "", "", "", 2) . " Pesos</td></tr>"; } else { echo '<tr><th nowrap="nowrap">' . $terminal->select_Paymentname(dol_getIdFromCode($db, $paym['type'], 'c_paiement')) . '</th><td nowrap="nowrap">' . price($paym['amount'] - ($diff_payment < 0 ? $diff_payment : 0), "", "", "", "", 2) . " Pesos</td></tr>"; } } if ($ban != 1) { echo '<tr><th nowrap="nowrap">' . ($diff_payment < 0 ? $langs->trans("CustomerRet") : $langs->trans("CustomerDeb")) . '</th><td nowrap="nowrap">' . price(abs($diff_payment), "", "", "", "", 2) . " Pesos</td></tr>"; } ?> </table> <div class="note"> <p> <?php print 'Nota: ' . $object->note; print $conf->global->POS_PREDEF_MSG; ?>
function import2Dolibarr($object, $typeimport) { global $conf; global $langs; $this->process_msg = ''; $error = 0; $fp = @fopen($this->filename, "r"); if ($fp) { switch ($object) { case 'ImportStock': $doliprod = new Product($this->db); $i = 0; while ($ligne = fgetcsv($fp, 1000, ";")) { $doliprod->id = ''; $i++; if ($this->firstline && $i == 1) { continue; } if ($conf->global->IMPORT_BARCODE) { $ligne[0] = $this->get_product_by_barcode($ligne[0]); } if ($doliprod->fetch('', $ligne[0]) <= 0) { $this->process_msg .= $langs->trans("ErrProdNoExist", $ligne[0], $doliprod->error) . "\n"; } else { $pid = $doliprod->id; $doliprod->ref = $ligne[0]; $entrepot = $ligne[1]; $newstock = $ligne[2]; $price = $ligne[3]; if ($conf->global->IMPORT_TOTAL_STOCK) { $doliprod->load_stock(); dol_syslog("stock produit " . $doliprod->stock_warehouse[$entrepot]->real . " entrepot " . $entrepot . " " . $doliprod->stock_reel, LOG_DEBUG); // correction de stock $delta = 0; if ($newstock > $doliprod->stock_warehouse[$entrepot]->real) { $delta = $newstock - $doliprod->stock_warehouse[$entrepot]->real; $sens = 0; } elseif ($newstock < $doliprod->stock_warehouse[$entrepot]->real) { $delta = $doliprod->stock_warehouse[$entrepot]->real - $newstock; $sens = 1; } if ($delta) { $res = $doliprod->correct_stock($this->user, $entrepot, $delta, $sens, $langs->trans("StockCorrection"), $price); if ($res < 0) { $this->process_msg .= $langs->trans("ErrMovStock", $ligne[0], $doliprod->error) . "\n"; $error++; } } dol_syslog("maj stock delta = " . $delta . " sens " . $sens, LOG_DEBUG); } else { $res = $doliprod->correct_stock($this->user, $entrepot, abs($newstock), $newstock > 0 ? 0 : 1, $langs->trans("StockCorrection"), $price); if ($res < 0) { $this->process_msg .= $langs->trans("ErrMovStock", $ligne[0], $doliprod->error) . "\n"; $error++; } } } } break; case 'ImportProduct': //$doliprod = new Product($this->db); $i = 0; while ($ligne = fgetcsv($fp, 1000, ";")) { $i++; $doliprod = new Product($this->db); $doliprod->id = ''; if ($this->firstline && $i == 1) { continue; } if ($doliprod->fetch('', $ligne[0]) < 0) { $this->process_msg .= $langs->trans("ErrProdNoExist", $ligne[0], $doliprod->error) . "\n"; } else { $pid = $doliprod->id; $doliprod->ref = $ligne[0]; if (!empty($ligne[1])) { $doliprod->libelle = $ligne[1]; } if (!empty($ligne[2])) { $doliprod->status = $ligne[2]; } $doliprod->status_buy = 1; if (!empty($ligne[3])) { $doliprod->description = $ligne[3]; } if (!empty($ligne[4])) { $doliprod->price = $ligne[4]; } if (!empty($ligne[5])) { $doliprod->tva_tx = $ligne[5]; } if (!empty($ligne[6])) { $doliprod->weight = $ligne[6]; } if (!empty($ligne[7])) { $doliprod->volume = $ligne[7]; } if (!empty($ligne[9])) { $doliprod->barcode = $ligne[9]; } if (!empty($ligne[9])) { $doliprod->barcode_type = dol_getIdFromCode($this->db, $ligne[10], 'c_barcode_type', 'libelle', 'rowid'); } if (!empty($ligne[10])) { $doliprod->type = $ligne[11]; } $doliprod->price_base_type = 'HT'; $this->db->begin; switch ($typeimport) { case 'C': if ($pid > 0) { if ($doliprod->update($pid, $this->user) < 0) { $this->process_msg .= $langs->trans("ErrProductUpdate", $ligne[0], $doliprod->error) . "\n"; $error++; } if ($doliprod->updatePrice($doliprod->price, $doliprod->price_base_type, $this->user) < 0) { $this->process_msg .= $langs->trans("ErrProductUpdate", $ligne[0], $doliprod->error) . "\n"; $error++; } } else { if ($doliprod->create($this->user) < 0) { $this->process_msg .= $langs->trans("ErrProductCreate", $ligne[0], $doliprod->error) . "\n"; $error++; } else { // image et code barre if ($ligne[8]) { $this->add_photo_web($conf->produit->dir_output, $ligne[8], $doliprod->id); } /*if ($ligne[9]) { if ($doliprod->setValueFrom('fk_barcode_type', 2) < 0){ $this->process_msg .= $langs->trans("ErrProductCreate", $ligne[0], $doliprod->error)."\n"; // TODO paramétrer $error++; } if ($doliprod->setValueFrom('barcode', $ligne[9]) < 0 ){ $this->process_msg .= $langs->trans("ErrProductCreate", $ligne[0], $doliprod->error)."\n"; $error++; } }*/ } } break; /*case 'M': if ($pid>0) { if ($doliprod->update($pid, $this->user) < 0){ $this->process_msg .= $langs->trans("ErrProductUpdate", $ligne[0], $doliprod->error)."\n"; $error++; } if (version_compare(DOL_VERSION, 3.5) >= 0){ if ($doliprod->updatePrice($doliprod->price, $doliprod->price_base_type, $this->user) < 0){ $this->process_msg .= $langs->trans("ErrProductUpdate", $ligne[0], $doliprod->error)."\n"; $error++; } } else{ if ($doliprod->updatePrice($doliprod->id, $doliprod->price, $doliprod->price_base_type, $this->user) < 0){ $this->process_msg .= $langs->trans("ErrProductUpdate", $ligne[0], $doliprod->error)."\n"; $error++; } } } else $this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("ErrProdNoExist", $ligne[0])."\n"; break;*/ /*case 'M': if ($pid>0) { if ($doliprod->update($pid, $this->user) < 0){ $this->process_msg .= $langs->trans("ErrProductUpdate", $ligne[0], $doliprod->error)."\n"; $error++; } if (version_compare(DOL_VERSION, 3.5) >= 0){ if ($doliprod->updatePrice($doliprod->price, $doliprod->price_base_type, $this->user) < 0){ $this->process_msg .= $langs->trans("ErrProductUpdate", $ligne[0], $doliprod->error)."\n"; $error++; } } else{ if ($doliprod->updatePrice($doliprod->id, $doliprod->price, $doliprod->price_base_type, $this->user) < 0){ $this->process_msg .= $langs->trans("ErrProductUpdate", $ligne[0], $doliprod->error)."\n"; $error++; } } } else $this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("ErrProdNoExist", $ligne[0])."\n"; break;*/ case 'D': if ($pid > 0) { if ($doliprod->delete($pid) < 0) { $this->process_msg .= $langs->trans("ErrProductDelete", $ligne[0], $doliprod->error) . "\n"; $error++; } } else { $this->process_msg .= $langs->trans("Untreated", $i) . ' ' . $langs->trans("ErrProdNoExist", $ligne[0]) . "\n"; } } if (!$error) { $this->db->commit(); } else { $this->db->rollback(); } } } // while break; case 'ImportThirtdparty': $i = 0; //$societe = new Societe($this->db); while ($ligne = fgetcsv($fp, 1000, ";")) { $i++; $societe = new Societe($this->db); if ($this->firstline && $i == 1) { continue; } if (!$ligne[0]) { $this->process_msg .= $langs->trans("Untreated", $i) . " " . $langs->trans("ErrNameRequired") . "\n"; continue; } // vérifier par code_client if ($ligne[13]) { $sid = $this->get_socbyclientcode($ligne[13]); } else { if ($ligne[14]) { $sid = $this->get_socbysuplliercode($ligne[14]); } } if ($sid > 0) { $societe->fetch($sid); } else { $sid = $societe->fetch('', $ligne[0]); } if ($ligne[12]) { $pid = dol_getIdFromCode($this->db, $ligne[12], "c_pays", "code", "rowid"); } else { $pid = ''; } if ($pid <= 0) { $pid = ''; } $did = ''; $societe->id = $sid; $societe->name = $ligne[0]; $societe->particulier = 0; //Société $societe->address = $ligne[1] . "\n" . $ligne[2] . "\n" . $ligne[3]; $societe->zip = $ligne[4]; $societe->town = $ligne[5]; $societe->state_id = $did; if ($ligne[12]) { $societe->country_code = $ligne[12]; } $societe->country_id = $pid; dol_syslog("codes {$pid} " . $lige[12], LOG_DEBUG); $societe->phone = $ligne[6]; $societe->fax = $ligne[7]; $societe->email = $ligne[8]; $societe->url = $ligne[9]; $societe->idprof1 = $ligne[10]; switch ($ligne[11]) { case '0': $societe->fournisseur = 0; $societe->client = $ligne[11]; break; case '1': $societe->fournisseur = 0; $societe->client = $ligne[11]; break; case '2': $societe->fournisseur = 0; $societe->client = $ligne[11]; break; case '10': $societe->client = 0; $societe->fournisseur = 1; break; default: break; } if ($ligne[13]) { $societe->code_client = $ligne[13]; } if ($ligne[14]) { $societe->code_fournisseur = $ligne[14]; } /*if ($ligne[15]) $societe->array_options["options_zone"]=$ligne[15]; if (!empty($ligne[16])) $societe->array_options["options_CA"]=$ligne[16]; if (!empty($ligne[17])) { if ($ligne[17] <= 5) $societe->effectif_id = 1; elseif ($ligne[17] <= 10) $societe->effectif_id = 2; elseif ($ligne[17] <= 50) $societe->effectif_id = 3; elseif ($ligne[17] <= 100) $societe->effectif_id = 4; elseif ($ligne[17] <= 500) $societe->effectif_id = 5; else $societe->effectif_id = 7; } dol_syslog("effectif " . $lige[17].' '.$societe->effectif_id." ".print_r($societe->array_options, true), LOG_DEBUG);*/ $this->db->begin; switch ($typeimport) { case 'C': if ($sid > 0) { if ($societe->update($sid, $this->user) < 0) { $this->process_msg .= $langs->trans("ErrCompanyUpdate", $ligne[0], $societe->error) . "\n"; $error++; } } elseif ($societe->create($this->user) < 0) { $this->process_msg .= $langs->trans("ErrCompanyCreate", $ligne[0], $societe->error) . "\n"; $error++; } break; /*case 'M': if ($sid>0) { if ($societe->update($sid, $this->user) < 0){ $this->process_msg .= $langs->trans("ErrCompanyUpdate", $ligne[0], $societe->error)."\n"; $error++; } } else $this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("CompanyNoExist", $ligne[0])."\n"; break;*/ /*case 'M': if ($sid>0) { if ($societe->update($sid, $this->user) < 0){ $this->process_msg .= $langs->trans("ErrCompanyUpdate", $ligne[0], $societe->error)."\n"; $error++; } } else $this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("CompanyNoExist", $ligne[0])."\n"; break;*/ case 'D': if ($sid > 0) { if ($societe->delete($sid) < 0) { $this->process_msg .= $langs->trans("ErrCompanyDelete", $ligne[0], $societe->error) . "\n"; $error++; } } else { $this->process_msg .= $langs->trans("Untreated", $i) . ' ' . $langs->trans("CompanyNoExist", $ligne[0]) . "\n"; } } if (!$error) { $this->db->commit(); } else { $this->db->rollback(); } } break; case 'ImportContact': $i = 0; //$contact=new Contact($this->db); //$societe = new Societe($this->db); while ($ligne = fgetcsv($fp, 1000, ";")) { $i++; $contact = new Contact($this->db); $societe = new Societe($this->db); if ($this->firstline && $i == 1) { continue; } //if ($societe->fetch('',$ligne[0]) < 0 ) $this->process_msg .= "erreur lecture Société "."\n"; if ($ligne[0]) { $socid = $this->get_socbyclientcode($ligne[0]); } else { if ($ligne[1]) { $socid = $this->get_socbysuplliercode($ligne[1]); } } if ($socid < 0) { $this->process_msg .= $i . " " . $langs->trans("ErrCompanyRequired") . "\n"; } else { $societe->fetch($socid); } if (!$societe->id) { $this->process_msg .= $langs->trans("ErrCompanyNoExist", $ligne[0] . " " . $ligne[1]) . "\n"; continue; } if (empty($ligne[2])) { $this->process_msg .= $langs->trans("Untreated", $i) . " " . $langs->trans("ErrNameRequired") . "\n"; continue; } $contactid = $this->get_contact_id($socid, $ligne[2], $ligne[3]); $contact->id = $contactid; $contact->civilite_id = $ligne[4]; $contact->lastname = $ligne[2]; $contact->firstname = $ligne[3]; if ($ligne[5] || $ligne[6] || $ligne[7]) { $contact->address = $ligne[5] . "\n" . $ligne[6] . "\n" . $ligne[7]; } else { $contact->address = $societe->address; } if ($ligne[8]) { $contact->zip = $ligne[8]; } else { $contact->zip = $societe->zip; } if ($ligne[9]) { $contact->town = $ligne[9]; } else { $contact->town = $societe->town; } if ($ligne[10]) { $pid = dol_getIdFromCode($this->db, $ligne[10], "c_pays", "code", "rowid"); if ($pid <= 0) { $pid = ''; } $contact->country_id = $pid; $contact->country_code = $ligne[10]; } else { $contact->country_id = $societe->country_id; $contact->country_code = $societe->country_code; } $contact->socid = $socid; // fk_soc $contact->status = 1; $contact->email = $ligne[11]; $contact->phone_pro = $ligne[12]; $contact->fax = $ligne[13]; $contact->phone_mobile = $ligne[14]; $contact->priv = 0; $this->db - begin; switch ($typeimport) { case 'C': if ($contactid > 0) { if ($contact->update($contactid, $this->user) < 0) { $this->process_msg .= $langs->trans("ErrContactUpdate", $ligne[2], $contact->error) . "\n"; $error++; } } elseif ($contact->create($this->user) < 0) { $this->process_msg .= $langs->trans("ErrContactCreate", $ligne[2], $contact->error) . "\n"; $error++; } break; /*case 'M': if ($contactid>0) { if ($contact->update($contactid, $this->user) < 0){ $this->process_msg .= $langs->trans("ErrContactUpdate", $ligne[2], $contact->error)."\n"; $error++; } } else $this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("ContactNoExist", $ligne[2])."\n"; break;*/ /*case 'M': if ($contactid>0) { if ($contact->update($contactid, $this->user) < 0){ $this->process_msg .= $langs->trans("ErrContactUpdate", $ligne[2], $contact->error)."\n"; $error++; } } else $this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("ContactNoExist", $ligne[2])."\n"; break;*/ case 'D': if ($contactid > 0) { if ($contact->delete($contactid) < 0) { $this->process_msg .= $langs->trans("ErrContactDelete", $ligne[2], $contact->error) . "\n"; $error++; } } else { $this->process_msg .= $langs->trans("Untreated", $i) . ' ' . $langs->trans("ContactNoExist", $ligne[2]) . "\n"; } } if (!$error) { $this->db->commit(); } else { $this->db->rollback(); } } break; /*case 'ImportActions': $i=0; $contact=new Contact($this->db); $societe = new Societe($this->db); $actioncomm = new ActionComm($this->db); $actuser = new User($this->db); while ($ligne = fgetcsv($fp,1000,";")) { $i++; if ($this->firstline && $i== 1) continue; //if ($societe->fetch('',$ligne[0]) < 0 ) $this->process_msg .= "erreur lecture Société "."\n"; //else $socid = $societe->id; $socid = $this->get_socbyclientcode($ligne[0]); if ($socid < 0 ) $this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("ErrCompanyRequired")."\n"; else $societe->fetch($socid); $socid = $societe->id; if (!$socid) { $this->process_msg .= $langs->trans("ErrCompanyNoExist", $ligne[0])."\n"; continue; } //action sur un contact de la soc if ($ligne[1]) { $contactid = $this->get_contact_id($socid, $ligne[1], $ligne[2]) ; if ($contactid < 0) { $this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("ContactNoExist", $ligne[1].' '. $ligne[2])."\n"; // réinitialiser ?? continue; } else $contact->fetch($contactid); } $usertodo = ''; if ($ligne[9]) { $usertodo=new User($this->db); if ( $usertodo->fetch('',$ligne[9]) < 0 ) $this->process_msg .= $langs->trans("ErrUserNoExist", $ligne[9])."\n"; } $userdone= '' ; if ($ligne[10]) { $usertodo=new User($this->db); if ( $usertodo->fetch('',$ligne[10]) < 0 ) $this->process_msg .= $langs->trans("ErrUserNoExist", $ligne[10])."\n"; } $datep = ''; if ($ligne[6]) { // voir date $n = sscanf($ligne[6],"%02d/%02d/%04d", $d_day, $d_mon, $d_year); if ($n==3) $datep=dol_mktime(12, 0, 0, $d_mon, $d_day, $d_year); if (!$datep) $this->process_msg .= $langs->trans("ErrDateConversion", $ligne[6])."\n"; } else $datep =''; $datef=''; if ($ligne[7]) { // voir la date $n = sscanf($ligne[7],"%02d/%02d/%04d", $d_day, $d_mon, $d_year); if ($n==3)$datef=dol_mktime(12, 0, 0, $d_mon, $d_day, $d_year); if (!$datef) $this->process_msg .= $langs->trans("ErrDateConversion", $ligne[7])."\n"; } else $datef =''; //$datef=''; $actioncomm->societe = $societe; if ($ligne[1]) $actioncomm->contact = $contact; else $actioncomm->contact = ''; $actioncomm->type_code = $ligne[3]; $actioncomm->priority = $ligne[4]; $actioncomm->location = '' ; $actioncomm->label = $ligne[5]; $actioncomm->datep = $datep; $actioncomm->datef = $datef; $actioncomm->percentage = $ligne[8]; $actioncomm->usertodo = $usertodo; $actioncomm->userdone = $userdone; $actioncomm->note =$ligne[11]; switch ($typeimport) { case 'C': $this->db->begin(); if ($actioncomm->add($this->user) < 0) { $this->process_msg .= $langs->trans("ErrActionCreate", $ligne[5], $actioncomm->error)."\n"; $this->db->rollback(); } else $this->db->commit(); break; case 'M': $this->db->begin(); if($actioncomm->update($user) < 0){ $this->process_msg .= $langs->trans("ErrActionUpdate", $ligne[5], $actioncomm->error)."\n"; $this->db->rollback(); } else $this->db->commit(); break; case 'D': $this->db->begin(); if($actioncomm->delete() < 0){ $this->process_msg .= $langs->trans("ErrActionDelete", $ligne[5], $actioncomm->error)."\n"; $this->db->rollback(); } else $this->db->commit(); break; } } break;*/ /*case 'ImportActions': $i=0; $contact=new Contact($this->db); $societe = new Societe($this->db); $actioncomm = new ActionComm($this->db); $actuser = new User($this->db); while ($ligne = fgetcsv($fp,1000,";")) { $i++; if ($this->firstline && $i== 1) continue; //if ($societe->fetch('',$ligne[0]) < 0 ) $this->process_msg .= "erreur lecture Société "."\n"; //else $socid = $societe->id; $socid = $this->get_socbyclientcode($ligne[0]); if ($socid < 0 ) $this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("ErrCompanyRequired")."\n"; else $societe->fetch($socid); $socid = $societe->id; if (!$socid) { $this->process_msg .= $langs->trans("ErrCompanyNoExist", $ligne[0])."\n"; continue; } //action sur un contact de la soc if ($ligne[1]) { $contactid = $this->get_contact_id($socid, $ligne[1], $ligne[2]) ; if ($contactid < 0) { $this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("ContactNoExist", $ligne[1].' '. $ligne[2])."\n"; // réinitialiser ?? continue; } else $contact->fetch($contactid); } $usertodo = ''; if ($ligne[9]) { $usertodo=new User($this->db); if ( $usertodo->fetch('',$ligne[9]) < 0 ) $this->process_msg .= $langs->trans("ErrUserNoExist", $ligne[9])."\n"; } $userdone= '' ; if ($ligne[10]) { $usertodo=new User($this->db); if ( $usertodo->fetch('',$ligne[10]) < 0 ) $this->process_msg .= $langs->trans("ErrUserNoExist", $ligne[10])."\n"; } $datep = ''; if ($ligne[6]) { // voir date $n = sscanf($ligne[6],"%02d/%02d/%04d", $d_day, $d_mon, $d_year); if ($n==3) $datep=dol_mktime(12, 0, 0, $d_mon, $d_day, $d_year); if (!$datep) $this->process_msg .= $langs->trans("ErrDateConversion", $ligne[6])."\n"; } else $datep =''; $datef=''; if ($ligne[7]) { // voir la date $n = sscanf($ligne[7],"%02d/%02d/%04d", $d_day, $d_mon, $d_year); if ($n==3)$datef=dol_mktime(12, 0, 0, $d_mon, $d_day, $d_year); if (!$datef) $this->process_msg .= $langs->trans("ErrDateConversion", $ligne[7])."\n"; } else $datef =''; //$datef=''; $actioncomm->societe = $societe; if ($ligne[1]) $actioncomm->contact = $contact; else $actioncomm->contact = ''; $actioncomm->type_code = $ligne[3]; $actioncomm->priority = $ligne[4]; $actioncomm->location = '' ; $actioncomm->label = $ligne[5]; $actioncomm->datep = $datep; $actioncomm->datef = $datef; $actioncomm->percentage = $ligne[8]; $actioncomm->usertodo = $usertodo; $actioncomm->userdone = $userdone; $actioncomm->note =$ligne[11]; switch ($typeimport) { case 'C': $this->db->begin(); if ($actioncomm->add($this->user) < 0) { $this->process_msg .= $langs->trans("ErrActionCreate", $ligne[5], $actioncomm->error)."\n"; $this->db->rollback(); } else $this->db->commit(); break; case 'M': $this->db->begin(); if($actioncomm->update($user) < 0){ $this->process_msg .= $langs->trans("ErrActionUpdate", $ligne[5], $actioncomm->error)."\n"; $this->db->rollback(); } else $this->db->commit(); break; case 'D': $this->db->begin(); if($actioncomm->delete() < 0){ $this->process_msg .= $langs->trans("ErrActionDelete", $ligne[5], $actioncomm->error)."\n"; $this->db->rollback(); } else $this->db->commit(); break; } } break;*/ case 'Importtarif': // ref four $i = 0; $this->process_msg = ''; $error = 0; /*$doliprod = new Product($this->db); $product = new ProductFournisseur($this->db); $societe = new Societe($this->db);*/ while ($ligne = fgetcsv($fp, 1000, ";")) { $doliprod->id = ''; $i++; $doliprod = new Product($this->db); $product = new ProductFournisseur($this->db); $societe = new Societe($this->db); if ($this->firstline && $i == 1) { continue; } // recherche du fournisseur if ($societe->fetch('', $ligne[2]) > 0) { $sid = $societe->id; } else { $this->process_msg .= $langs->trans("Untreated", $i) . " " . $langs->trans("ErrComppanyNoExist", $ligne[2]) . "\n"; $sid = ''; } if ($doliprod->fetch('', $ligne[0]) > 0) { $pid = $doliprod->id; } else { $this->process_msg .= $langs->trans("Untreated", $i) . " " . $langs->trans("ErrProductNoExist", $ligne[0], $doliprod->error) . "\n"; $pid = ''; } if ($sid > 0 && $pid > 0) { $result = $product->fetch($doliprod->id); if ($result > 0) { $this->db->begin(); switch ($typeimport) { case 'C': $ret = $product->add_fournisseur($this->user, $sid, $ligne[1], $ligne[3]); if ($ret < 0 && $ret != -3) { $this->process_msg .= $langs->trans("Untreated", $i) . " " . $langs->trans("ErrCreatePrice", $product->error) . "\n"; $error++; } $ret = $product->update_buyprice($ligne[3], $ligne[4], $this->user, 'HT', $supplier, '', $ligne[1], $ligne[5]); if ($ret < 0 && $ret != -3) { $this->process_msg .= $langs->trans("Untreated", $i) . " " . $langs->trans("ErrCreatePrice", $product->error) . "\n"; $error++; } break; /*case 'M': { // gestion du prix obligatoire $supplier=new Fournisseur($this->db); $result=$supplier->fetch($sid); $ret=$product->update_buyprice($ligne[3], $ligne[4] , $this->user, 'HT', $supplier, '', $ligne[1], $ligne[5] ); if ($ret < 0) { $this->process_msg .= $langs->trans("Untreated", $i)." ".$langs->trans("Qty").$ligne[3]. ", ".$langs->trans("Price").$ligne[4]." ".$langs->trans("ErrUpdatePrice", $product->error)."\n"; $error ++; } } break;*/ /*case 'M': { // gestion du prix obligatoire $supplier=new Fournisseur($this->db); $result=$supplier->fetch($sid); $ret=$product->update_buyprice($ligne[3], $ligne[4] , $this->user, 'HT', $supplier, '', $ligne[1], $ligne[5] ); if ($ret < 0) { $this->process_msg .= $langs->trans("Untreated", $i)." ".$langs->trans("Qty").$ligne[3]. ", ".$langs->trans("Price").$ligne[4]." ".$langs->trans("ErrUpdatePrice", $product->error)."\n"; $error ++; } } break;*/ case 'D': // suprresion de la ligne avec le même nb d'article et le même prix $sql = "SELECT pfp.rowid FROM " . MAIN_DB_PREFIX . "product_fournisseur_price as pfp"; $sql .= " WHERE pfp.quantity = '" . $ligne[3] . "' AND pfp.ref_fourn = '" . $ligne[1]; $sql .= "' AND pfp.fk_soc = '" . $sid . "' AND pfp.fk_product='" . $pid . "'"; $sql .= " AND pfp.entity = " . $conf->entity; $resql = $this->db->query($sql); if ($resql) { $obj = $this->db->fetch_object($resql); if ($obj->rowid > 0) { $result = $product->remove_product_fournisseur_price($obj->rowid); } else { $this->process_msg .= $langs->trans("Untreated", $i) . ' ' . $langs->trans("ErrDeletePrice", $product->error) . "\n"; $error++; } } else { $this->process_msg .= "Error SQL= " . $sql . "\n"; $error++; } break; } //switch } if (!$error) { $this->db->commit(); } else { $this->db->rollback(); } } // fournisseur trouvé } // traitement ligne // while reffour break; } // fin switch fclose($fp); } else { $this->error = $langs->trans("ErrOpenFile") . $nomfich; $error = -1; } return $error; }
/** * Create a withdrawal request for a standing order * * @param User $fuser User asking standing order * @param float $amount Amount we request withdraw for * @return int <0 if KO, >0 if OK */ function demande_prelevement($fuser, $amount = 0) { global $langs; $error = 0; dol_syslog(get_class($this) . "::demande_prelevement", LOG_DEBUG); if ($this->statut > self::STATUS_DRAFT && $this->paye == 0) { require_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php'; $bac = new CompanyBankAccount($this->db); $bac->fetch(0, $this->socid); $sql = 'SELECT count(*)'; $sql .= ' FROM ' . MAIN_DB_PREFIX . 'prelevement_facture_demande'; $sql .= ' WHERE fk_facture = ' . $this->id; $sql .= ' AND traite = 0'; dol_syslog(get_class($this) . "::demande_prelevement", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $row = $this->db->fetch_row($resql); if ($row[0] == 0) { $now = dol_now(); $totalpaye = $this->getSommePaiement(); $totalcreditnotes = $this->getSumCreditNotesUsed(); $totaldeposits = $this->getSumDepositsUsed(); //print "totalpaye=".$totalpaye." totalcreditnotes=".$totalcreditnotes." totaldeposts=".$totaldeposits; // We can also use bcadd to avoid pb with floating points // For example print 239.2 - 229.3 - 9.9; does not return 0. //$resteapayer=bcadd($this->total_ttc,$totalpaye,$conf->global->MAIN_MAX_DECIMALS_TOT); //$resteapayer=bcadd($resteapayer,$totalavoir,$conf->global->MAIN_MAX_DECIMALS_TOT); if (empty($amount)) { $amount = price2num($this->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits, 'MT'); } if (is_numeric($amount) && $amount != 0) { $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . 'prelevement_facture_demande'; $sql .= ' (fk_facture, amount, date_demande, fk_user_demande, code_banque, code_guichet, number, cle_rib)'; $sql .= ' VALUES (' . $this->id; $sql .= ",'" . price2num($amount) . "'"; $sql .= ",'" . $this->db->idate($now) . "'"; $sql .= "," . $fuser->id; $sql .= ",'" . $bac->code_banque . "'"; $sql .= ",'" . $bac->code_guichet . "'"; $sql .= ",'" . $bac->number . "'"; $sql .= ",'" . $bac->cle_rib . "')"; dol_syslog(get_class($this) . "::demande_prelevement", LOG_DEBUG); $resql = $this->db->query($sql); if (!$resql) { $this->error = $this->db->lasterror(); dol_syslog(get_class($this) . '::demandeprelevement Erreur'); $error++; } } else { $this->error = 'WithdrawRequestErrorNilAmount'; dol_syslog(get_class($this) . '::demandeprelevement WithdrawRequestErrorNilAmount'); $error++; } if (!$error) { // Force payment mode of invoice to withdraw $payment_mode_id = dol_getIdFromCode($this->db, 'PRE', 'c_paiement'); if ($payment_mode_id > 0) { $result = $this->setPaymentMethods($payment_mode_id); } } if ($error) { return -1; } return 1; } else { $this->error = "A request already exists"; dol_syslog(get_class($this) . '::demandeprelevement Impossible de creer une demande, demande deja en cours'); return 0; } } else { $this->error = $this->db->error(); dol_syslog(get_class($this) . '::demandeprelevement Erreur -2'); return -2; } } else { $this->error = "Status of invoice does not allow this"; dol_syslog(get_class($this) . "::demandeprelevement " . $this->error . " {$this->statut}, {$this->paye}, {$this->mode_reglement_id}"); return -3; } }
/** * Return HTML table with list of projects and number of opened tasks * * @param DoliDB $db Database handler * @param Form $form Object form * @param int $socid Id thirdparty * @param int $projectsListId Id of project I have permission on * @param int $mytasks Limited to task I am contact to * @param int $statut -1=No filter on statut, 0 or 1 = Filter on status * @param array $listofoppstatus List of opportunity status * @param array $hiddenfields List of info to not show ('projectlabel', 'declaredprogress', '...', ) * @return void */ function print_projecttasks_array($db, $form, $socid, $projectsListId, $mytasks = 0, $statut = -1, $listofoppstatus = array(), $hiddenfields = array()) { global $langs, $conf, $user, $bc; require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php'; $projectstatic = new Project($db); $thirdpartystatic = new Societe($db); $sortfield = ''; $sortorder = ''; $project_year_filter = 0; $title = $langs->trans("Projects"); if (strcmp($statut, '') && $statut >= 0) { $title = $langs->trans("Projects") . ' ' . $langs->trans($projectstatic->statuts_long[$statut]); } $arrayidtypeofcontact = array(); print '<table class="noborder" width="100%">'; $sql .= " FROM " . MAIN_DB_PREFIX . "projet as p"; if ($mytasks) { $sql .= ", " . MAIN_DB_PREFIX . "projet_task as t"; $sql .= ", " . MAIN_DB_PREFIX . "element_contact as ec"; $sql .= ", " . MAIN_DB_PREFIX . "c_type_contact as ctc"; } else { $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "projet_task as t ON p.rowid = t.fk_projet"; } $sql .= " WHERE p.entity = " . $conf->entity; $sql .= " AND p.rowid IN (" . $projectsListId . ")"; if ($socid) { $sql .= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = " . $socid . ")"; } if ($mytasks) { $sql .= " AND p.rowid = t.fk_projet"; $sql .= " AND ec.element_id = t.rowid"; $sql .= " AND ec.fk_socpeople = " . $user->id; $sql .= " AND ec.fk_c_type_contact = ctc.rowid"; // Replace the 2 lines with ec.fk_c_type_contact in $arrayidtypeofcontact $sql .= " AND ctc.element = 'project_task'"; } if ($statut >= 0) { $sql .= " AND p.fk_statut = " . $statut; } if (!empty($conf->global->PROJECT_LIMIT_YEAR_RANGE)) { $project_year_filter = GETPOST("project_year_filter"); //Check if empty or invalid year. Wildcard ignores the sql check if ($project_year_filter != "*") { if (empty($project_year_filter) || !ctype_digit($project_year_filter)) { $project_year_filter = date("Y"); } $sql .= " AND (p.dateo IS NULL OR p.dateo <= " . $db->idate(dol_get_last_day($project_year_filter, 12, false)) . ")"; $sql .= " AND (p.datee IS NULL OR p.datee >= " . $db->idate(dol_get_first_day($project_year_filter, 1, false)) . ")"; } } // Get id of project we must show tasks $arrayidofprojects = array(); $sql1 = "SELECT p.rowid as projectid"; $sql1 .= $sql; $resql = $db->query($sql1); if ($resql) { $i = 0; $num = $db->num_rows($resql); while ($i < $num) { $objp = $db->fetch_object($resql); $arrayidofprojects[$objp->projectid] = $objp->projectid; $i++; } } else { dol_print_error($db); } if (empty($arrayidofprojects)) { $arrayidofprojects[0] = -1; } // Get list of project with calculation on tasks $sql2 = "SELECT p.rowid as projectid, p.ref, p.title, p.fk_soc, s.nom as socname, p.fk_user_creat, p.public, p.fk_statut as status, p.fk_opp_status as opp_status, p.opp_amount,"; $sql2 .= " COUNT(t.rowid) as nb, SUM(t.planned_workload) as planned_workload, SUM(t.planned_workload * t.progress / 100) as declared_progess_workload"; $sql2 .= " FROM " . MAIN_DB_PREFIX . "projet as p"; $sql2 .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid = p.fk_soc"; $sql2 .= " LEFT JOIN " . MAIN_DB_PREFIX . "projet_task as t ON p.rowid = t.fk_projet"; $sql2 .= " WHERE p.rowid IN (" . join(',', $arrayidofprojects) . ")"; $sql2 .= " GROUP BY p.rowid, p.ref, p.title, p.fk_soc, p.fk_user_creat, p.public, p.fk_statut, p.fk_opp_status, p.opp_amount"; $sql2 .= " ORDER BY p.title, p.ref"; $var = true; $resql = $db->query($sql2); if ($resql) { $total_task = 0; $total_opp_amount = 0; $ponderated_opp_amount = 0; $num = $db->num_rows($resql); $i = 0; print '<tr class="liste_titre">'; print_liste_field_titre($title . ' <span class="badge">' . $num . '</span>', $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder); print_liste_field_titre($langs->trans("ThirdParty"), $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder); if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) { print_liste_field_titre($langs->trans("OpportunityAmount"), "", "", "", "", 'align="right"', $sortfield, $sortorder); print_liste_field_titre($langs->trans("OpportunityStatus"), "", "", "", "", 'align="right"', $sortfield, $sortorder); } if (empty($conf->global->PROJECT_HIDE_TASKS)) { print_liste_field_titre($langs->trans("Tasks"), "", "", "", "", 'align="right"', $sortfield, $sortorder); if (!in_array('plannedworkload', $hiddenfields)) { print_liste_field_titre($langs->trans("PlannedWorkload"), "", "", "", "", 'align="right"', $sortfield, $sortorder); } if (!in_array('declaredprogress', $hiddenfields)) { print_liste_field_titre($langs->trans("ProgressDeclared"), "", "", "", "", 'align="right"', $sortfield, $sortorder); } } print_liste_field_titre($langs->trans("Status"), "", "", "", "", 'align="right"', $sortfield, $sortorder); print "</tr>\n"; while ($i < $num) { $objp = $db->fetch_object($resql); $projectstatic->id = $objp->projectid; $projectstatic->user_author_id = $objp->fk_user_creat; $projectstatic->public = $objp->public; // Check is user has read permission on project $userAccess = $projectstatic->restrictedProjectArea($user); if ($userAccess >= 0) { $var = !$var; print "<tr " . $bc[$var] . ">"; print '<td>'; $projectstatic->ref = $objp->ref; print $projectstatic->getNomUrl(1); if (!in_array('projectlabel', $hiddenfields)) { print ' - ' . dol_trunc($objp->title, 24); } print '</td>'; print '<td>'; if ($objp->fk_soc > 0) { $thirdpartystatic->id = $objp->fk_soc; $thirdpartystatic->ref = $objp->socname; $thirdpartystatic->name = $objp->socname; print $thirdpartystatic->getNomUrl(1); } print '</td>'; if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) { print '<td align="right">'; if ($objp->opp_amount) { print price($objp->opp_amount, 0, '', 1, -1, -1, $conf->currency); } print '</td>'; print '<td align="right">'; $code = dol_getIdFromCode($db, $objp->opp_status, 'c_lead_status', 'rowid', 'code'); if ($code) { print $langs->trans("OppStatus" . $code); } print '</td>'; } $projectstatic->statut = $objp->status; if (empty($conf->global->PROJECT_HIDE_TASKS)) { print '<td align="right">' . $objp->nb . '</td>'; $plannedworkload = $objp->planned_workload; $total_plannedworkload += $plannedworkload; if (!in_array('plannedworkload', $hiddenfields)) { print '<td align="right">' . ($plannedworkload ? convertSecondToTime($plannedworkload) : '') . '</td>'; } if (!in_array('declaredprogress', $hiddenfields)) { $declaredprogressworkload = $objp->declared_progess_workload; $total_declaredprogressworkload += $declaredprogressworkload; print '<td align="right">'; //print $objp->planned_workload.'-'.$objp->declared_progess_workload."<br>"; print $plannedworkload ? round(100 * $declaredprogressworkload / $plannedworkload, 0) . '%' : ''; print '</td>'; } } print '<td align="right">' . $projectstatic->getLibStatut(3) . '</td>'; print "</tr>\n"; $total_task = $total_task + $objp->nb; $total_opp_amount = $total_opp_amount + $objp->opp_amount; $ponderated_opp_amount = $ponderated_opp_amount + price2num($listofoppstatus[$objp->opp_status] * $objp->opp_amount / 100); } $i++; } print '<tr class="liste_total">'; print '<td colspan="2">' . $langs->trans("Total") . "</td>"; if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) { print '<td class="liste_total" align="right">' . price($total_opp_amount, 0, '', 1, -1, -1, $conf->currency) . '</td>'; print '<td class="liste_total" align="right">' . $form->textwithpicto(price($ponderated_opp_amount, 0, '', 1, -1, -1, $conf->currency), $langs->trans("OpportunityPonderatedAmountDesc"), 1) . '</td>'; } if (empty($conf->global->PROJECT_HIDE_TASKS)) { print '<td class="liste_total" align="right">' . $total_task . '</td>'; if (!in_array('plannedworkload', $hiddenfields)) { print '<td class="liste_total" align="right">' . ($total_plannedworkload ? convertSecondToTime($total_plannedworkload) : '') . '</td>'; } if (!in_array('declaredprogress', $hiddenfields)) { print '<td class="liste_total" align="right">' . ($total_plannedworkload ? round(100 * $total_declaredprogressworkload / $total_plannedworkload, 0) . '%' : '') . '</td>'; } } print '<td class="liste_total"></td>'; print '</tr>'; $db->free($resql); } else { dol_print_error($db); } print "</table>"; if (!empty($conf->global->PROJECT_LIMIT_YEAR_RANGE)) { //Add the year filter input print '<form method="get" action="' . $_SERVER["PHP_SELF"] . '">'; print '<table width="100%">'; print '<tr>'; print '<td>' . $langs->trans("Year") . '</td>'; print '<td style="text-align:right"><input type="text" size="4" class="flat" name="project_year_filter" value="' . $project_year_filter . '"/>'; print "</tr>\n"; print '</table></form>'; } }
/** * Load data control * * @param int $action Action code * @return void */ function doActions(&$action) { global $conf, $user, $langs; if ($_POST["getcustomercode"]) { // We defined value code_client $_POST["code_client"] = "Acompleter"; } if ($_POST["getsuppliercode"]) { // We defined value code_fournisseur $_POST["code_fournisseur"] = "Acompleter"; } // Add new third party if (!$_POST["getcustomercode"] && !$_POST["getsuppliercode"] && ($action == 'add' || $action == 'update')) { require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php'; $error = 0; if (GETPOST("private") == 1) { $this->object->particulier = GETPOST("private"); $this->object->name = empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION) ? trim($_POST["firstname"] . ' ' . $_POST["lastname"]) : trim($_POST["lastname"] . ' ' . $_POST["firstname"]); $this->object->civility_id = $_POST["civility_id"]; // Add non official properties $this->object->name_bis = $_POST["lastname"]; $this->object->firstname = $_POST["firstname"]; } else { $this->object->name = $_POST["nom"]; } $this->object->address = $_POST["adresse"]; $this->object->zip = $_POST["zipcode"]; $this->object->town = $_POST["town"]; $this->object->country_id = $_POST["country_id"]; $this->object->state_id = $_POST["state_id"]; $this->object->phone = $_POST["tel"]; $this->object->fax = $_POST["fax"]; $this->object->email = trim($_POST["email"]); $this->object->url = $_POST["url"]; $this->object->idprof1 = $_POST["idprof1"]; $this->object->idprof2 = $_POST["idprof2"]; $this->object->idprof3 = $_POST["idprof3"]; $this->object->idprof4 = $_POST["idprof4"]; $this->object->prefix_comm = $_POST["prefix_comm"]; $this->object->code_client = $_POST["code_client"]; $this->object->code_fournisseur = $_POST["code_fournisseur"]; $this->object->capital = $_POST["capital"]; $this->object->barcode = $_POST["barcode"]; $this->object->canvas = GETPOST("canvas"); $this->object->tva_assuj = $_POST["assujtva_value"]; // Local Taxes $this->object->localtax1_assuj = $_POST["localtax1assuj_value"]; $this->object->localtax2_assuj = $_POST["localtax2assuj_value"]; $this->object->tva_intra = $_POST["tva_intra"]; $this->object->forme_juridique_code = $_POST["forme_juridique_code"]; $this->object->effectif_id = $_POST["effectif_id"]; if (GETPOST("private") == 1) { $this->object->typent_id = dol_getIdFromCode($db, 'TE_PRIVATE', 'c_typent'); } else { $this->object->typent_id = $_POST["typent_id"]; } $this->object->client = $_POST["client"]; $this->object->fournisseur = $_POST["fournisseur"]; $this->object->commercial_id = $_POST["commercial_id"]; $this->object->default_lang = $_POST["default_lang"]; // Check parameters if (empty($_POST["cancel"])) { if (!empty($this->object->email) && !isValidEMail($this->object->email)) { $error = 1; $langs->load("errors"); $this->error = $langs->trans("ErrorBadEMail", $this->object->email); $action = $action == 'add' ? 'create' : 'edit'; } if (!empty($this->object->url) && !isValidUrl($this->object->url)) { $error = 1; $langs->load("errors"); $this->error = $langs->trans("ErrorBadUrl", $this->object->url); $action = $action == 'add' ? 'create' : 'edit'; } if ($this->object->fournisseur && !$conf->fournisseur->enabled) { $error = 1; $langs->load("errors"); $this->error = $langs->trans("ErrorSupplierModuleNotEnabled"); $action = $action == 'add' ? 'create' : 'edit'; } } if (!$error) { if ($action == 'add') { $this->db->begin(); if (empty($this->object->client)) { $this->object->code_client = ''; } if (empty($this->object->fournisseur)) { $this->object->code_fournisseur = ''; } $result = $this->object->create($user); if ($result >= 0) { if ($this->object->particulier) { dol_syslog(get_class($this) . "::doActions This thirdparty is a personal people", LOG_DEBUG); $contact = new Contact($this->db); $contact->civility_id = $this->object->civility_id; $contact->name = $this->object->name_bis; $contact->firstname = $this->object->firstname; $contact->address = $this->object->address; $contact->zip = $this->object->zip; $contact->town = $this->object->town; $contact->country_id = $this->object->country_id; $contact->socid = $this->object->id; // fk_soc $contact->status = 1; $contact->email = $this->object->email; $contact->priv = 0; $result = $contact->create($user); } } else { $this->errors = $this->object->errors; } if ($result >= 0) { $this->db->commit(); if ($this->object->client == 1) { header("Location: " . DOL_URL_ROOT . "/comm/fiche.php?socid=" . $this->object->id); return; } else { if ($this->object->fournisseur == 1) { header("Location: " . DOL_URL_ROOT . "/fourn/fiche.php?socid=" . $this->object->id); return; } else { header("Location: " . $_SERVER["PHP_SELF"] . "?socid=" . $this->object->id); return; } } exit; } else { $this->db->rollback(); $this->errors = $this->object->errors; $action = 'create'; } } if ($action == 'update') { if ($_POST["cancel"]) { header("Location: " . $_SERVER["PHP_SELF"] . "?socid=" . $this->object->id); exit; } $oldsoccanvas = dol_clone($this->object); // To avoid setting code if third party is not concerned. But if it had values, we keep them. if (empty($this->object->client) && empty($oldsoccanvas->code_client)) { $this->object->code_client = ''; } if (empty($this->object->fournisseur) && empty($oldsoccanvas->code_fournisseur)) { $this->object->code_fournisseur = ''; } $result = $this->object->update($this->object->id, $user, 1, $oldsoccanvas->codeclient_modifiable(), $oldsoccanvas->codefournisseur_modifiable()); if ($result >= 0) { header("Location: " . $_SERVER["PHP_SELF"] . "?socid=" . $this->object->id); exit; } else { $reload = 0; $this->errors = $this->object->errors; $action = "edit"; } } } } if ($action == 'confirm_delete' && GETPOST("confirm") == 'yes') { $result = $this->object->delete($this->object->id); if ($result >= 0) { header("Location: " . DOL_URL_ROOT . "/societe/societe.php?delsoc=" . $this->object->nom . ""); exit; } else { $reload = 0; $this->errors = $this->object->errors; $action = ''; } } /* * Generate document */ if ($action == 'builddoc') { if (is_numeric(GETPOST('model'))) { $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Model")); } else { require_once DOL_DOCUMENT_ROOT . '/core/modules/societe/modules_societe.class.php'; $this->object->fetch_thirdparty(); // Define output language $outputlangs = $langs; $newlang = ''; if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) { $newlang = GETPOST('lang_id'); } if ($conf->global->MAIN_MULTILANGS && empty($newlang)) { $newlang = $this->object->default_lang; } if (!empty($newlang)) { $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); } $result = thirdparty_doc_create($this->db, $this->object->id, '', GETPOST('model', 'alpha'), $outputlangs); if ($result <= 0) { dol_print_error($this->db, $result); exit; } } } }
/** * Check if notification are active for couple action/company. * If yes, send mail and save trace into llx_notify. * * @param string $notifcode Code of action in llx_c_action_trigger (new usage) or Id of action in llx_c_action_trigger (old usage) * @param Object $object Object the notification deals on * @return int <0 if KO, or number of changes if OK */ function send($notifcode, $object) { global $user, $conf, $langs, $mysoc, $dolibarr_main_url_root; include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; dol_syslog(get_class($this) . "::send notifcode=" . $notifcode . ", object=" . $object->id); $langs->load("other"); // Define $urlwithroot $urlwithouturlroot = preg_replace('/' . preg_quote(DOL_URL_ROOT, '/') . '$/i', '', trim($dolibarr_main_url_root)); $urlwithroot = $urlwithouturlroot . DOL_URL_ROOT; // This is to use external domain name found into config file //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current // Define some vars $application = $mysoc->name; //if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $application = $conf->global->MAIN_APPLICATION_TITLE; $replyto = $conf->notification->email_from; $filename = basename($file); $mimefile = dol_mimetype($file); $object_type = ''; $link = ''; $num = 0; if (!in_array($notifcode, array('BILL_VALIDATE', 'ORDER_VALIDATE', 'PROPAL_VALIDATE', 'FICHINTER_VALIDATE', 'ORDER_SUPPLIER_VALIDATE', 'ORDER_SUPPLIER_APPROVE', 'ORDER_SUPPLIER_REFUSE', 'SHIPPING_VALIDATE'))) { return 0; } $oldref = empty($object->oldref) ? $object->ref : $object->oldref; $newref = empty($object->newref) ? $object->ref : $object->newref; // Check notification per third party $sql = "SELECT s.nom, c.email, c.rowid as cid, c.lastname, c.firstname, c.default_lang,"; $sql .= " a.rowid as adid, a.label, a.code, n.rowid, n.type"; $sql .= " FROM " . MAIN_DB_PREFIX . "socpeople as c,"; $sql .= " " . MAIN_DB_PREFIX . "c_action_trigger as a,"; $sql .= " " . MAIN_DB_PREFIX . "notify_def as n,"; $sql .= " " . MAIN_DB_PREFIX . "societe as s"; $sql .= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action"; $sql .= " AND n.fk_soc = s.rowid"; if (is_numeric($notifcode)) { $sql .= " AND n.fk_action = " . $notifcode; } else { $sql .= " AND a.code = '" . $notifcode . "'"; } // New usage $sql .= " AND s.rowid = " . $object->socid; $result = $this->db->query($sql); if ($result) { $num = $this->db->num_rows($result); if ($num > 0) { $i = 0; while ($i < $num && !$error) { $obj = $this->db->fetch_object($result); $sendto = dolGetFirstLastname($obj->firstname, $obj->lastname) . " <" . $obj->email . ">"; $notifcodedefid = $obj->adid; if (dol_strlen($obj->email)) { // Set output language $outputlangs = $langs; if ($obj->default_lang && $obj->default_lang != $langs->defaultlang) { $outputlangs = new Translate('', $conf); $outputlangs->setDefaultLang($obj->default_lang); } switch ($notifcode) { case 'BILL_VALIDATE': $link = '/compta/facture.php?facid=' . $object->id; $dir_output = $conf->facture->dir_output; $object_type = 'facture'; $mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated", $newref); break; case 'ORDER_VALIDATE': $link = '/commande/card.php?id=' . $object->id; $dir_output = $conf->commande->dir_output; $object_type = 'order'; $mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated", $newref); break; case 'PROPAL_VALIDATE': $link = '/comm/propal.php?id=' . $object->id; $dir_output = $conf->propal->dir_output; $object_type = 'propal'; $mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated", $newref); break; case 'FICHINTER_VALIDATE': $link = '/fichinter/card.php?id=' . $object->id; $dir_output = $conf->facture->dir_output; $object_type = 'ficheinter'; $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated", $object->ref); break; case 'ORDER_SUPPLIER_VALIDATE': $link = '/fourn/commande/card.php?id=' . $object->id; $dir_output = $conf->fournisseur->dir_output . '/commande/'; $object_type = 'order_supplier'; $mesg = $langs->transnoentitiesnoconv("Hello") . ",\n\n"; $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderValidatedBy", $object->ref, $user->getFullName($langs)); $mesg .= "\n\n" . $langs->transnoentitiesnoconv("Sincerely") . ".\n\n"; break; case 'ORDER_SUPPLIER_APPROVE': $link = '/fourn/commande/card.php?id=' . $object->id; $dir_output = $conf->fournisseur->dir_output . '/commande/'; $object_type = 'order_supplier'; $mesg = $langs->transnoentitiesnoconv("Hello") . ",\n\n"; $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy", $newref, $user->getFullName($langs)); $mesg .= "\n\n" . $langs->transnoentitiesnoconv("Sincerely") . ".\n\n"; break; case 'ORDER_SUPPLIER_REFUSE': $link = '/fourn/commande/card.php?id=' . $object->id; $dir_output = $conf->fournisseur->dir_output . '/commande/'; $object_type = 'order_supplier'; $mesg = $langs->transnoentitiesnoconv("Hello") . ",\n\n"; $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy", $newref, $user->getFullName($langs)); $mesg .= "\n\n" . $langs->transnoentitiesnoconv("Sincerely") . ".\n\n"; break; case 'SHIPPING_VALIDATE': $dir_output = $conf->expedition->dir_output . '/sending/'; $object_type = 'order_supplier'; $mesg = $langs->transnoentitiesnoconv("EMailTextExpeditionValidated", $newref); break; } $ref = dol_sanitizeFileName($newref); $pdf_path = $dir_output . "/" . $ref . "/" . $ref . ".pdf"; if (!dol_is_file($pdf_path)) { // We can't add PDF as it is not generated yet. $filepdf = ''; } else { $filepdf = $pdf_path; } $subject = '[' . $application . '] ' . $outputlangs->transnoentitiesnoconv("DolibarrNotification"); $message = $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification", $application, $mysoc->name) . "\n"; $message .= $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification2", $application, $mysoc->name) . "\n"; $message .= "\n"; $message .= $mesg; if ($link) { $message = dol_concatdesc($message, $urlwithroot . $link); } $mailfile = new CMailFile($subject, $sendto, $replyto, $message, array($file), array($mimefile), array($filename[count($filename) - 1]), '', '', 0, -1); if ($mailfile->sendfile()) { $sql = "INSERT INTO " . MAIN_DB_PREFIX . "notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, objet_id, email)"; $sql .= " VALUES ('" . $this->db->idate(dol_now()) . "', " . $notifcodedefid . ", " . $object->socid . ", " . $obj->cid . ", '" . $obj->type . "', '" . $object_type . "', " . $object->id . ", '" . $this->db->escape($obj->email) . "')"; if (!$this->db->query($sql)) { dol_print_error($this->db); } } else { $error++; $this->errors[] = $mailfile->error; } } else { dol_syslog("No notification sent for " . $sendto . " because email is empty"); } $i++; } } else { dol_syslog("No notification to thirdparty sent, nothing into notification setup for the thirdparty socid = " . $object->socid); } } else { $error++; $this->errors[] = $this->db->lasterror(); return -1; } // Check notification using fixed email if (!$error) { foreach ($conf->global as $key => $val) { if ($val == '' || !preg_match('/^NOTIFICATION_FIXEDEMAIL_' . $notifcode . '_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) { continue; } $threshold = (double) $reg[1]; if ($object->total_ht <= $threshold) { dol_syslog("A notification is requested for notifcode = " . $notifcode . " but amount = " . $object->total_ht . " so lower than threshold = " . $threshold . ". We discard this notification"); continue; } $param = 'NOTIFICATION_FIXEDEMAIL_' . $notifcode . '_THRESHOLD_HIGHER_' . $reg[1]; $sendto = $conf->global->{$param}; $notifcodedefid = dol_getIdFromCode($this->db, $notifcode, 'c_action_trigger', 'code', 'rowid'); if ($notifcodedefid <= 0) { dol_print_error($this->db, 'Failed to get id from code'); } $object_type = ''; $link = ''; $num++; switch ($notifcode) { case 'BILL_VALIDATE': $link = '/compta/facture.php?facid=' . $object->id; $dir_output = $conf->facture->dir_output; $object_type = 'facture'; $mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated", $newref); break; case 'ORDER_VALIDATE': $link = '/commande/card.php?id=' . $object->id; $dir_output = $conf->commande->dir_output; $object_type = 'order'; $mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated", $newref); break; case 'PROPAL_VALIDATE': $link = '/comm/propal.php?id=' . $object->id; $dir_output = $conf->propal->dir_output; $object_type = 'propal'; $mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated", $newref); break; case 'FICHINTER_VALIDATE': $link = '/fichinter/card.php?id=' . $object->id; $dir_output = $conf->facture->dir_output; $object_type = 'ficheinter'; $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated", $newref); break; case 'ORDER_SUPPLIER_VALIDATE': $link = '/fourn/commande/card.php?id=' . $object->id; $dir_output = $conf->fournisseur->dir_output . '/commande/'; $object_type = 'order_supplier'; $mesg = $langs->transnoentitiesnoconv("Hello") . ",\n\n"; $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderValidatedBy", $newref, $user->getFullName($langs)); $mesg .= "\n\n" . $langs->transnoentitiesnoconv("Sincerely") . ".\n\n"; break; case 'ORDER_SUPPLIER_APPROVE': $link = '/fourn/commande/card.php?id=' . $object->id; $dir_output = $conf->fournisseur->dir_output . '/commande/'; $object_type = 'order_supplier'; $mesg = $langs->transnoentitiesnoconv("Hello") . ",\n\n"; $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy", $newref, $user->getFullName($langs)); $mesg .= "\n\n" . $langs->transnoentitiesnoconv("Sincerely") . ".\n\n"; break; case 'ORDER_SUPPLIER_APPROVE2': $link = '/fourn/commande/card.php?id=' . $object->id; $dir_output = $conf->fournisseur->dir_output . '/commande/'; $object_type = 'order_supplier'; $mesg = $langs->transnoentitiesnoconv("Hello") . ",\n\n"; $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy", $newref, $user->getFullName($langs)); $mesg .= "\n\n" . $langs->transnoentitiesnoconv("Sincerely") . ".\n\n"; break; case 'ORDER_SUPPLIER_REFUSE': $link = '/fourn/commande/card.php?id=' . $object->id; $dir_output = $conf->fournisseur->dir_output . '/commande/'; $object_type = 'order_supplier'; $mesg = $langs->transnoentitiesnoconv("Hello") . ",\n\n"; $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy", $newref, $user->getFullName($langs)); $mesg .= "\n\n" . $langs->transnoentitiesnoconv("Sincerely") . ".\n\n"; break; case 'SHIPPING_VALIDATE': $dir_output = $conf->expedition->dir_output . '/sending/'; $object_type = 'order_supplier'; $mesg = $langs->transnoentitiesnoconv("EMailTextExpeditionValidated", $newref); break; } $ref = dol_sanitizeFileName($newref); $pdf_path = $dir_output . "/" . $ref . "/" . $ref . ".pdf"; if (!dol_is_file($pdf_path)) { // We can't add PDF as it is not generated yet. $filepdf = ''; } else { $filepdf = $pdf_path; } $subject = '[' . $application . '] ' . $langs->transnoentitiesnoconv("DolibarrNotification"); $message = $langs->transnoentities("YouReceiveMailBecauseOfNotification", $application, $mysoc->name) . "\n"; $message .= $langs->transnoentities("YouReceiveMailBecauseOfNotification2", $application, $mysoc->name) . "\n"; $message .= "\n"; $message .= $mesg; if ($link) { $message = dol_concatdesc($message, $urlwithroot . $link); } // Replace keyword __SUPERVISOREMAIL__ if (preg_match('/__SUPERVISOREMAIL__/', $sendto)) { $newval = ''; if ($user->fk_user > 0) { $supervisoruser = new User($this->db); $supervisoruser->fetch($user->fk_user); if ($supervisoruser->email) { $newval = trim(dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname) . ' <' . $supervisoruser->email . '>'); } } dol_syslog("Replace the __SUPERVISOREMAIL__ key into recipient email string with " . $newval); $sendto = preg_replace('/__SUPERVISOREMAIL__/', $newval, $sendto); $sendto = preg_replace('/^[\\s,]+/', '', $sendto); // Clean start of string $sendto = preg_replace('/[\\s,]+$/', '', $sendto); // Clean end of string } if ($sendto) { $mailfile = new CMailFile($subject, $sendto, $replyto, $message, array($file), array($mimefile), array($filename[count($filename) - 1]), '', '', 0, -1); if ($mailfile->sendfile()) { $sql = "INSERT INTO " . MAIN_DB_PREFIX . "notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, objet_id, email)"; $sql .= " VALUES ('" . $this->db->idate(dol_now()) . "', " . $notifcodedefid . ", " . $object->socid . ", null, 'email', '" . $object_type . "', " . $object->id . ", '" . $this->db->escape($conf->global->{$param}) . "')"; if (!$this->db->query($sql)) { dol_print_error($this->db); } } else { $error++; $this->errors[] = $mailfile->error; } } } } if (!$error) { return $num; } else { return -1 * $error; } }
$valsamount[$obj->opp_status] = $obj->opp_amount; $totalnb += $obj->nb; $totalamount += $obj->opp_amount; $ponderated_opp_amount = $ponderated_opp_amount + price2num($listofoppstatus[$obj->opp_status] * $obj->opp_amount / 100); $total += $row[0]; } $i++; } $db->free($resql); print '<table class="noborder nohover" width="100%">'; print '<tr class="liste_titre"><td colspan="2">' . $langs->trans("Statistics") . ' - ' . $langs->trans("OpportunitiesStatusForOpenedProjects") . '</td></tr>' . "\n"; $var = true; $listofstatus = array_keys($listofoppstatus); foreach ($listofstatus as $status) { $labelstatus = ''; $code = dol_getIdFromCode($db, $status, 'c_lead_status', 'rowid', 'code'); if ($code) { $labelstatus = $langs->trans("OppStatus" . $code); } if (empty($labelstatus)) { $labelstatus = $listofopplabel[$status]; } //$labelstatus .= ' ('.$langs->trans("Coeff").': '.price2num($listofoppstatus[$status]).')'; $labelstatus .= ' - ' . price2num($listofoppstatus[$status]) . '%'; $dataseries[] = array('label' => $labelstatus, 'data' => isset($valsamount[$status]) ? (double) $valsamount[$status] : 0); if (!$conf->use_javascript_ajax) { $var = !$var; print "<tr " . $bc[$var] . ">"; print '<td>' . $labelstatus . '</td>'; print '<td align="right"><a href="list.php?statut=' . $status . '">' . price(isset($valsamount[$status]) ? (double) $valsamount[$status] : 0, 0, '', 1, -1, -1, $conf->currency) . '</a></td>'; print "</tr>\n";
} /* * Actions */ $parameters = array(); $reshook = $hookmanager->executeHooks('doActions', $parameters); // 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_changeselectedfields.inc.php'; if (empty($reshook)) { if ($action == 'setstcomm') { $object = new Client($db); $result = $object->fetch(GETPOST('stcommsocid')); $object->stcomm_id = dol_getIdFromCode($db, GETPOST('stcomm', 'alpha'), 'c_stcomm'); $result = $object->set_commnucation_level($user); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } $action = ''; } } // Do we click on purge search criteria ? if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) { $search_categ = ''; $search_sale = ''; $search_barcode = ""; $search_customer_code = ''; $search_supplier_code = ''; $search_account_customer_code = '';
} // Le reste propre a cette action s'affiche en bas de page. } /* * Action confirm_paiement */ if ($action == 'confirm_paiement' && $confirm == 'yes') { $error = 0; $datepaye = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); $db->begin(); // Creation of payment line $paiement = new Paiement($db); $paiement->datepaye = $datepaye; $paiement->amounts = $amounts; // Array with all payments dispatching $paiement->paiementid = dol_getIdFromCode($db, $_POST['paiementcode'], 'c_paiement'); $paiement->num_paiement = $_POST['num_paiement']; $paiement->note = $_POST['comment']; if (!$error) { $paiement_id = $paiement->create($user, GETPOST('closepaidinvoices') == 'on' ? 1 : 0); if ($paiement_id < 0) { $errmsg = $paiement->error; $error++; } } if (!$error) { $result = $paiement->addPaymentToBank($user, 'payment', '(CustomerInvoicePayment)', $_POST['accountid'], $_POST['chqemetteur'], $_POST['chqbank']); if ($result < 0) { $errmsg = $paiement->error; $error++; }
/** * Return HTML table with list of projects and number of opened tasks * * @param DoliDB $db Database handler * @param Form $form Object form * @param int $socid Id thirdparty * @param int $projectsListId Id of project i have permission on * @param int $mytasks Limited to task i am contact to * @param int $statut -1=No filter on statut, 0 or 1 = Filter on status * @param array $listofoppstatus List of opportunity status * @return void */ function print_projecttasks_array($db, $form, $socid, $projectsListId, $mytasks = 0, $statut = -1, $listofoppstatus = array()) { global $langs, $conf, $user, $bc; require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php'; $projectstatic = new Project($db); $sortfield = ''; $sortorder = ''; $project_year_filter = 0; $title = $langs->trans("Projects"); if (strcmp($statut, '') && $statut >= 0) { $title = $langs->trans("Projects") . ' ' . $langs->trans($projectstatic->statuts_long[$statut]); } print '<table class="noborder" width="100%">'; print '<tr class="liste_titre">'; print_liste_field_titre($title, "index.php", "", "", "", "", $sortfield, $sortorder); if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) { print_liste_field_titre($langs->trans("OpportunityAmount"), "", "", "", "", 'align="right"', $sortfield, $sortorder); print_liste_field_titre($langs->trans("OpportunityStatus"), "", "", "", "", 'align="right"', $sortfield, $sortorder); } if (empty($conf->global->PROJECT_HIDE_TASKS)) { print_liste_field_titre($langs->trans("Tasks"), "", "", "", "", 'align="right"', $sortfield, $sortorder); } print_liste_field_titre($langs->trans("Status"), "", "", "", "", 'align="right"', $sortfield, $sortorder); print "</tr>\n"; $sql = "SELECT p.rowid as projectid, p.ref, p.title, p.fk_user_creat, p.public, p.fk_statut as status, p.fk_opp_status as opp_status, p.opp_amount, COUNT(DISTINCT t.rowid) as nb"; // We use DISTINCT here because line can be doubled if task has 2 links to same user $sql .= " FROM " . MAIN_DB_PREFIX . "projet as p"; if ($mytasks) { $sql .= ", " . MAIN_DB_PREFIX . "projet_task as t"; $sql .= ", " . MAIN_DB_PREFIX . "element_contact as ec"; $sql .= ", " . MAIN_DB_PREFIX . "c_type_contact as ctc"; } else { $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "projet_task as t ON p.rowid = t.fk_projet"; } $sql .= " WHERE p.entity = " . $conf->entity; $sql .= " AND p.rowid IN (" . $projectsListId . ")"; if ($socid) { $sql .= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = " . $socid . ")"; } if ($mytasks) { $sql .= " AND p.rowid = t.fk_projet"; $sql .= " AND ec.element_id = t.rowid"; $sql .= " AND ctc.rowid = ec.fk_c_type_contact"; $sql .= " AND ctc.element = 'project_task'"; $sql .= " AND ec.fk_socpeople = " . $user->id; } if ($statut >= 0) { $sql .= " AND p.fk_statut = " . $statut; } if (!empty($conf->global->PROJECT_LIMIT_YEAR_RANGE)) { $project_year_filter = GETPOST("project_year_filter"); //Check if empty or invalid year. Wildcard ignores the sql check if ($project_year_filter != "*") { if (empty($project_year_filter) || !ctype_digit($project_year_filter)) { $project_year_filter = date("Y"); } $sql .= " AND (p.dateo IS NULL OR p.dateo <= " . $db->idate(dol_get_last_day($project_year_filter, 12, false)) . ")"; $sql .= " AND (p.datee IS NULL OR p.datee >= " . $db->idate(dol_get_first_day($project_year_filter, 1, false)) . ")"; } } $sql .= " GROUP BY p.rowid, p.ref, p.title, p.fk_user_creat, p.public, p.fk_statut, p.fk_opp_status, p.opp_amount"; $sql .= " ORDER BY p.title, p.ref"; $var = true; $resql = $db->query($sql); if ($resql) { $total_task = 0; $total_opp_amount = 0; $ponderated_opp_amount = 0; $num = $db->num_rows($resql); $i = 0; while ($i < $num) { $objp = $db->fetch_object($resql); $projectstatic->id = $objp->projectid; $projectstatic->user_author_id = $objp->fk_user_creat; $projectstatic->public = $objp->public; // Check is user has read permission on project $userAccess = $projectstatic->restrictedProjectArea($user); if ($userAccess >= 0) { $var = !$var; print "<tr " . $bc[$var] . ">"; print '<td class="nowrap">'; $projectstatic->ref = $objp->ref; print $projectstatic->getNomUrl(1); print ' - ' . dol_trunc($objp->title, 24) . '</td>'; if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) { print '<td align="right">'; if ($objp->opp_amount) { print price($objp->opp_amount, 0, '', 1, -1, -1, $conf->currency); } print '</td>'; print '<td align="right">'; $code = dol_getIdFromCode($db, $objp->opp_status, 'c_lead_status', 'rowid', 'code'); if ($code) { print $langs->trans("OppStatus" . $code); } print '</td>'; } $projectstatic->statut = $objp->status; if (empty($conf->global->PROJECT_HIDE_TASKS)) { print '<td align="right">' . $objp->nb . '</td>'; } print '<td align="right">' . $projectstatic->getLibStatut(3) . '</td>'; print "</tr>\n"; $total_task = $total_task + $objp->nb; $total_opp_amount = $total_opp_amount + $objp->opp_amount; $ponderated_opp_amount = $ponderated_opp_amount + price2num($listofoppstatus[$objp->opp_status] * $objp->opp_amount / 100); } $i++; } print '<tr><td>' . $langs->trans("Total") . "</td>"; if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) { print '<td align="right">' . price($total_opp_amount, 0, '', 1, -1, -1, $conf->currency) . '</td>'; print '<td align="right">' . $form->textwithpicto(price($ponderated_opp_amount, 0, '', 1, -1, -1, $conf->currency), $langs->trans("OpportunityPonderatedAmount"), 1) . '</td>'; } if (empty($conf->global->PROJECT_HIDE_TASKS)) { print '<td align="right">' . $total_task . '</td>'; } $db->free($resql); } else { dol_print_error($db); } print "</table>"; if (!empty($conf->global->PROJECT_LIMIT_YEAR_RANGE)) { //Add the year filter input print '<form method="get" action="' . $_SERVER["PHP_SELF"] . '">'; print '<table width="100%">'; print '<tr>'; print '<td>' . $langs->trans("Year") . '</td>'; print '<td style="text-align:right"><input type="text" size="4" class="flat" name="project_year_filter" value="' . $project_year_filter . '"/>'; print "</tr>\n"; print '</table></form>'; } }