function createFacture(&$object, &$TLine) { global $user, $conf, $langs, $db; dol_include_once('/fourn/class/fournisseur.facture.class.php'); $facture = new FactureFournisseur($db); $facture->origin = $object->element; $facture->origin_id = $object->id; $facture->ref = ''; $facture->ref_supplier = ''; //$facture->ref_supplier = $object->ref_supplier; $facture->socid = $object->socid; $facture->libelle = $object->libelle; $object->date = time(); $facture->note_public = $object->note_public; $facture->note_private = $object->note_private; $facture->cond_reglement_id = $object->cond_reglement_id; $facture->fk_account = $object->fk_account; $facture->fk_project = empty($object->fk_project) ? null : $object->fk_project; $facture->fk_incoterms = $object->fk_incoterms; $facture->location_incoterms = $object->location_incoterms; $facture->ref_supplier = time(); $facture->date_echeance = $facture->calculate_date_lim_reglement(); foreach ($TLine as &$row) { $line = $row->line; $line->qty = $row->qty; $line->id = 0; $facture->lines[] = $line; } $res = $facture->create($user); if ($res > 0) { header('location:' . dol_buildpath('/fourn/facture/card.php?action=editref_supplier&id=' . $res, 1)); exit; } else { //var_dump($res, $facture); setEventMessage("ImpossibleToCreateInvoice", "errors"); } }
if ($page == -1) { $page = 0; } $offset = $conf->liste_limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; if (!$sortorder) { $sortorder = "DESC"; } if (!$sortfield) { $sortfield = "f.datef"; } /* * View */ $supplierinvoicestatic = new FactureFournisseur($db); $form = new Form($db); if ($id > 0 || !empty($ref)) { $product = new Product($db); $result = $product->fetch($id, $ref); $parameters = array('id' => $id); $reshook = $hookmanager->executeHooks('doActions', $parameters, $product, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } llxHeader("", "", $langs->trans("CardProduct" . $product->type)); if ($result > 0) { /* * En mode visu */
if ($user->societe_id > 0) { $action = ''; $socid = $user->societe_id; } /* * View */ $now=gmmktime(); llxHeader('',$langs->trans("BillsSuppliersUnpaid")); $facturestatic=new FactureFournisseur($db); $companystatic=new Societe($db); /*************************************************************************** * * * Mode Liste * * * ***************************************************************************/ $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); if ($page == -1) { $page = 0; } $offset = $conf->liste_limit * $page; $pageprev = $page - 1;
/** * Load data into info_box_contents array to show array later. * * @param int $max Maximum number of records to load * @return void */ function loadBox($max = 5) { global $conf, $user, $langs, $db; $this->max = $max; include_once DOL_DOCUMENT_ROOT . "/fourn/class/fournisseur.facture.class.php"; $facturestatic = new FactureFournisseur($db); $this->info_box_head = array('text' => $langs->trans("BoxTitleLastSupplierBills", $max)); if ($user->rights->fournisseur->facture->lire) { $sql = "SELECT s.nom, s.rowid as socid,"; $sql .= " f.rowid as facid, f.facnumber, f.amount,"; $sql .= " f.paye, f.fk_statut,"; $sql .= ' f.datef as df,'; $sql .= ' f.datec as datec,'; $sql .= ' f.date_lim_reglement as datelimite, f.tms, f.type'; $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s"; $sql .= ", " . MAIN_DB_PREFIX . "facture_fourn as f"; if (!$user->rights->societe->client->voir && !$user->societe_id) { $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; } $sql .= " WHERE f.fk_soc = s.rowid"; $sql .= " AND f.entity = " . $conf->entity; if (!$user->rights->societe->client->voir && !$user->societe_id) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = "******" AND s.rowid = " . $user->societe_id; } $sql .= " ORDER BY f.tms DESC"; $sql .= $db->plimit($max, 0); $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); $now = dol_now(); $i = 0; $l_due_date = $langs->trans('Late') . ' (' . strtolower($langs->trans('DateEcheance')) . ': %s)'; while ($i < $num) { $objp = $db->fetch_object($result); $datelimite = $db->jdate($objp->datelimite); $datec = $db->jdate($objp->datec); $late = ''; if ($objp->paye == 0 && $datelimite < $now - $conf->facture->fournisseur->warning_delay) { $late = img_warning(sprintf($l_due_date, dol_print_date($datelimite, 'day'))); } $this->info_box_contents[$i][0] = array('td' => 'align="left" width="16"', 'logo' => $this->boximg, 'url' => DOL_URL_ROOT . "/fourn/facture/fiche.php?facid=" . $objp->facid); $this->info_box_contents[$i][1] = array('td' => 'align="left"', 'text' => $objp->facnumber, 'text2' => $late, 'url' => DOL_URL_ROOT . "/fourn/facture/fiche.php?facid=" . $objp->facid); $this->info_box_contents[$i][2] = array('td' => 'align="left" width="16"', 'logo' => 'company', 'url' => DOL_URL_ROOT . "/fourn/fiche.php?socid=" . $objp->socid); $this->info_box_contents[$i][3] = array('td' => 'align="left"', 'text' => $objp->nom, 'url' => DOL_URL_ROOT . "/fourn/fiche.php?socid=" . $objp->socid); $this->info_box_contents[$i][4] = array('td' => 'align="right"', 'text' => dol_print_date($datec, 'day')); $fac = new FactureFournisseur($db); $fac->fetch($objp->facid); $alreadypaid = $fac->getSommePaiement(); $this->info_box_contents[$i][5] = array('td' => 'align="right" width="18"', 'text' => $facturestatic->LibStatut($objp->paye, $objp->fk_statut, 3, $alreadypaid, $objp->type)); $i++; } if ($num == 0) { $this->info_box_contents[$i][0] = array('td' => 'align="center"', 'text' => $langs->trans("NoModifiedSupplierBills")); } } else { dol_print_error($db); } } else { $this->info_box_contents[0][0] = array('td' => 'align="left"', 'text' => $langs->transnoentities("ReadPermissionNotAllowed")); } }
* Main */ @set_time_limit(0); print "***** " . $script_file . " (" . $version . ") pid=" . dol_getmypid() . " *****\n"; dol_syslog($script_file . " launched with arg " . join(',', $argv)); if (!isset($argv[3]) || !$argv[3]) { print "Usage: " . $script_file . " bank_ref [bank_receipt_number|all] (csv|tsv|excel|excel2007) [lang=xx_XX]\n"; exit(-1); } $bankref = $argv[1]; $num = $argv[2]; $model = $argv[3]; $newlangid = 'en_EN'; // To force a new lang id $invoicestatic = new Facture($db); $invoicesupplierstatic = new FactureFournisseur($db); $societestatic = new Societe($db); $chargestatic = new ChargeSociales($db); $memberstatic = new Adherent($db); $paymentstatic = new Paiement($db); $paymentsupplierstatic = new PaiementFourn($db); $paymentsocialcontributionstatic = new PaymentSocialContribution($db); $paymentvatstatic = new Tva($db); $bankstatic = new Account($db); $banklinestatic = new AccountLine($db); // Parse parameters foreach ($argv as $key => $value) { $found = false; // Define options if (preg_match('/^lang=/i', $value)) { $found = true;
$num = $db->num_rows($resql); $i = 0; $total = 0; print '<b>' . $langs->trans("Invoices") . '</b><br>'; print '<table class="noborder" width="100%">'; print '<tr class="liste_titre">'; print '<td>' . $langs->trans('Ref') . '</td>'; print '<td>' . $langs->trans('RefSupplier') . '</td>'; print '<td>' . $langs->trans('Company') . '</td>'; print '<td align="right">' . $langs->trans('ExpectedToPay') . '</td>'; print '<td align="center">' . $langs->trans('Status') . '</td>'; print '<td align="right">' . $langs->trans('PayedByThisPayment') . '</td>'; print "</tr>\n"; if ($num > 0) { $var = True; $facturestatic = new FactureFournisseur($db); while ($i < $num) { $objp = $db->fetch_object($resql); $var = !$var; print '<tr ' . $bc[$var] . '>'; // Ref print '<td><a href="' . DOL_URL_ROOT . '/fourn/facture/fiche.php?facid=' . $objp->facid . '">' . img_object($langs->trans('ShowBill'), 'bill') . ' '; print $objp->ref; print "</a></td>\n"; // Ref supplier print '<td>' . $objp->ref_supplier . "</td>\n"; // Third party print '<td><a href="' . DOL_URL_ROOT . '/fourn/fiche.php?socid=' . $objp->socid . '">' . img_object($langs->trans('ShowCompany'), 'company') . ' ' . $objp->nom . '</a></td>'; // Expected to pay print '<td align="right">' . price($objp->total_ttc) . '</td>'; // Status
print ' (' . $langs->transnoentities("InvoiceHasAvoir"); $i = 0; foreach ($facidavoir as $id) { if ($i == 0) { print ' '; } else { print ','; } $facavoir = new FactureFournisseur($db); $facavoir->fetch($id); print $facavoir->getNomUrl(1); } print ')'; } if (isset($facidnext) && $facidnext > 0) { $facthatreplace = new FactureFournisseur($db); $facthatreplace->fetch($facidnext); print ' (' . $langs->transnoentities("ReplacedByInvoice", $facthatreplace->getNomUrl(1)) . ')'; } print '</td></tr>'; // Label print '<tr><td>' . $form->editfieldkey("Label", 'label', $object->label, $object, $user->rights->fournisseur->facture->creer) . '</td>'; print '<td colspan="3">' . $form->editfieldval("Label", 'label', $object->label, $object, $user->rights->fournisseur->facture->creer) . '</td>'; /* * List of payments */ $nbrows = 9; $nbcols = 2; if (!empty($conf->projet->enabled)) { $nbrows++; }
/** * Get list of invoices for third party * * @param array $authentication Array of authentication information * @param int $idthirdparty Id thirdparty * @return array Array result * */ function getSupplierInvoicesForThirdParty($authentication,$idthirdparty) { global $db,$conf,$langs; dol_syslog("Function: getSupplierInvoicesForThirdParty login="******" idthirdparty=".$idthirdparty); if ($authentication['entity']) $conf->entity=$authentication['entity']; // Init and check authentication $objectresp=array(); $errorcode='';$errorlabel=''; $error=0; $fuser=check_authentication($authentication,$error,$errorcode,$errorlabel); // Check parameters if (! $error && empty($idthirdparty)) { $error++; $errorcode='BAD_PARAMETERS'; $errorlabel='Parameter id is not provided'; } if (! $error) { $linesinvoice=array(); $sql.='SELECT f.rowid as facid'; $sql.=' FROM '.MAIN_DB_PREFIX.'facture_fourn as f'; //$sql.=', '.MAIN_DB_PREFIX.'societe as s'; //$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pt.fk_product = p.rowid'; //$sql.=" WHERE f.fk_soc = s.rowid AND nom = '".$db->escape($idthirdparty)."'"; //$sql.=" WHERE f.fk_soc = s.rowid AND nom = '".$db->escape($idthirdparty)."'"; $sql.=" WHERE f.entity = ".$conf->entity; if ($idthirdparty != 'all') $sql.=" AND f.fk_soc = ".$db->escape($idthirdparty); $resql=$db->query($sql); if ($resql) { $num=$db->num_rows($resql); $i=0; while ($i < $num) { // En attendant remplissage par boucle $obj=$db->fetch_object($resql); $invoice=new FactureFournisseur($db); $invoice->fetch($obj->facid); // Define lines of invoice $linesresp=array(); foreach($invoice->lines as $line) { $linesresp[]=array( 'id'=>$line->rowid, 'type'=>$line->product_type, 'desc'=>dol_htmlcleanlastbr($line->description), 'total_net'=>$line->total_ht, 'total_vat'=>$line->total_tva, 'total'=>$line->total_ttc, 'vat_rate'=>$line->tva_tx, 'qty'=>$line->qty, 'product_ref'=>$line->product_ref, 'product_label'=>$line->product_label, 'product_desc'=>$line->product_desc, ); } // Now define invoice $linesinvoice[]=array( 'id'=>$invoice->id, 'ref'=>$invoice->ref, 'ref_supplier'=>$invoice->ref_supplier, 'ref_ext'=>$invoice->ref_ext, 'fk_user_author' => $invoice->fk_user_author, 'fk_user_valid' => $invoice->fk_user_valid, 'fk_thirdparty' => $invoice->fk_soc, 'type'=>$invoice->type, 'status'=>$invoice->statut, 'total_net'=>$invoice->total_ht, 'total_vat'=>$invoice->total_tva, 'total'=>$invoice->total_ttc, 'date_creation'=>dol_print_date($invoice->datec,'dayhourrfc'), 'date_modification'=>dol_print_date($invoice->tms,'dayhourrfc'), 'date_invoice'=>dol_print_date($invoice->date,'dayhourrfc'), 'date_term'=>dol_print_date($invoice->date_echeance,'dayhourrfc'), 'label'=>$invoice->libelle, 'paid'=>$invoice->paye, 'note'=>$invoice->note, 'note_public'=>$invoice->note_public, 'close_code'=>$invoice->close_code, 'close_note'=>$invoice->close_note, 'lines' => $linesresp ); $i++; } $objectresp=array( 'result'=>array('result_code'=>'OK', 'result_label'=>''), 'invoices'=>$linesinvoice ); } else { $error++; $errorcode=$db->lasterrno(); $errorlabel=$db->lasterror(); } } if ($error) { $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel)); } return $objectresp; }
/** * Show top header of page. * * @param PDF $pdf Object PDF * @param FactureFournisseur $object Object to show * @param int $showaddress 0=no, 1=yes * @param Translate $outputlangs Object lang for output * @return void */ function _pagehead(&$pdf, $object, $showaddress, $outputlangs) { global $langs, $conf, $mysoc; $outputlangs->load("main"); $outputlangs->load("bills"); $outputlangs->load("orders"); $outputlangs->load("companies"); $default_font_size = pdf_getPDFFontSize($outputlangs); // Do not add the BACKGROUND as this is for suppliers //pdf_pagehead($pdf,$outputlangs,$this->page_hauteur); $pdf->SetTextColor(0, 0, 60); $pdf->SetFont('', 'B', $default_font_size + 3); $posy = $this->marge_haute; $posx = $this->page_largeur - $this->marge_droite - 100; $pdf->SetXY($this->marge_gauche, $posy); // Logo /* $logo=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo; if ($mysoc->logo) { if (is_readable($logo)) { $height=pdf_getHeightForLogo($logo); $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto) } else { $pdf->SetTextColor(200,0,0); $pdf->SetFont('','B', $default_font_size - 2); $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L'); $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToModuleSetup"), 0, 'L'); } } else {*/ $text = $this->emetteur->name; $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L'); //} $pdf->SetFont('', 'B', $default_font_size + 3); $pdf->SetXY($posx, $posy); $pdf->SetTextColor(0, 0, 60); $pdf->MultiCell(100, 3, $outputlangs->transnoentities("SupplierInvoice") . " " . $outputlangs->convToOutputCharset($object->ref), '', 'R'); $posy += 1; if ($object->ref_supplier) { $posy += 4; $pdf->SetFont('', 'B', $default_font_size); $pdf->SetXY($posx, $posy); $pdf->SetTextColor(0, 0, 60); $pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefSupplier") . " : " . $object->ref_supplier, '', 'R'); $posy += 1; } $pdf->SetFont('', '', $default_font_size - 1); if (!empty($conf->global->PDF_SHOW_PROJECT)) { $object->fetch_projet(); if (!empty($object->project->ref)) { $posy += 4; $pdf->SetXY($posx, $posy); $langs->load("projects"); $pdf->SetTextColor(0, 0, 60); $pdf->MultiCell(100, 3, $outputlangs->transnoentities("Project") . " : " . (empty($object->project->ref) ? '' : $object->projet->ref), '', 'R'); } } if ($object->date) { $posy += 4; $pdf->SetXY($posx, $posy); $pdf->SetTextColor(0, 0, 60); $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Date") . " : " . dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R'); } else { $posy += 4; $pdf->SetXY($posx, $posy); $pdf->SetTextColor(255, 0, 0); $pdf->MultiCell(100, 4, strtolower($outputlangs->transnoentities("OrderToProcess")), '', 'R'); } if ($object->thirdparty->code_fournisseur) { $posy += 4; $pdf->SetXY($posx, $posy); $pdf->SetTextColor(0, 0, 60); $pdf->MultiCell(100, 3, $outputlangs->transnoentities("SupplierCode") . " : " . $outputlangs->transnoentities($object->thirdparty->code_fournisseur), '', 'R'); } $posy += 1; $pdf->SetTextColor(0, 0, 60); // Show list of linked objects $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size); if ($showaddress) { // Sender properties $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->client); // Show sender $posy = 42; $posx = $this->marge_gauche; if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) { $posx = $this->page_largeur - $this->marge_droite - 80; } $hautcadre = 40; // Show sender frame $pdf->SetTextColor(0, 0, 0); $pdf->SetFont('', '', $default_font_size - 2); $pdf->SetXY($posx, $posy - 5); $pdf->MultiCell(66, 5, $outputlangs->transnoentities("BillFrom") . ":", 0, 'L'); $pdf->SetXY($posx, $posy); $pdf->SetFillColor(230, 230, 230); $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1); $pdf->SetTextColor(0, 0, 60); // Show sender name $pdf->SetXY($posx + 2, $posy + 3); $pdf->SetFont('', 'B', $default_font_size); $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L'); $posy = $pdf->getY(); // Show sender information $pdf->SetXY($posx + 2, $posy); $pdf->SetFont('', '', $default_font_size - 1); $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L'); // If BILLING contact defined on invoice, we use it $usecontact = false; $arrayidcontact = $object->getIdContact('internal', 'BILLING'); if (count($arrayidcontact) > 0) { $usecontact = true; $result = $object->fetch_contact($arrayidcontact[0]); } //Recipient name // On peut utiliser le nom de la societe du contact if ($usecontact && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) { $thirdparty = $object->contact; } else { $thirdparty = $mysoc; } $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs); $carac_client = pdf_build_address($outputlangs, $this->emetteur, $mysoc, !empty($object->contact) ? $object->contact : null, $usecontact, 'target'); // Show recipient $widthrecbox = 100; if ($this->page_largeur < 210) { $widthrecbox = 84; } // To work with US executive format $posy = 42; $posx = $this->page_largeur - $this->marge_droite - $widthrecbox; if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) { $posx = $this->marge_gauche; } // Show recipient frame $pdf->SetTextColor(0, 0, 0); $pdf->SetFont('', '', $default_font_size - 2); $pdf->SetXY($posx + 2, $posy - 5); $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo") . ":", 0, 'L'); $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre); // Show recipient name $pdf->SetXY($posx + 2, $posy + 3); $pdf->SetFont('', 'B', $default_font_size); $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L'); $posy = $pdf->getY(); // Show recipient information $pdf->SetFont('', '', $default_font_size - 1); $pdf->SetXY($posx + 2, $posy); $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L'); } }
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php'; require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; $langs->load("suppliers"); $langs->load("orders"); $langs->load("companies"); // Security check $socid = isset($_GET["socid"]) ? $_GET["socid"] : ''; if ($user->societe_id) { $socid = $user->societe_id; } $result = restrictedArea($user, 'societe', $socid, ''); /* * View */ $commandestatic = new CommandeFournisseur($db); $facturestatic = new FactureFournisseur($db); $companystatic = new Societe($db); llxHeader("", $langs->trans("SuppliersArea")); print_fiche_titre($langs->trans("SuppliersArea")); //print '<table border="0" width="100%" class="notopnoleftnoright">'; //print '<tr><td valign="top" width="30%" class="notopnoleft">'; print '<div class="fichecenter"><div class="fichethirdleft">'; // Orders $commande = new CommandeFournisseur($db); $sql = "SELECT count(cf.rowid), cf.fk_statut"; $sql .= " FROM " . MAIN_DB_PREFIX . "commande_fournisseur as cf,"; $sql .= " " . MAIN_DB_PREFIX . "societe as s"; if (!$user->rights->societe->client->voir && !$socid) { $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as sc ON s.rowid = sc.fk_soc"; } $sql .= " WHERE cf.fk_soc = s.rowid ";
include_once DOL_DOCUMENT_ROOT . '/contrat/class/contrat.class.php'; $board = new Contrat($db); $dashboardlines[] = $board->load_board($user, "inactives"); // Number of active services (expired) $dashboardlines[] = $board->load_board($user, "expired"); } // Number of invoices customers (has paid) if (!empty($conf->facture->enabled) && $user->rights->facture->lire) { include_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php'; $board = new Facture($db); $dashboardlines[] = $board->load_board($user); } // Number of supplier invoices (has paid) if (!empty($conf->fournisseur->enabled) && !empty($conf->facture->enabled) && $user->rights->facture->lire) { include_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php'; $board = new FactureFournisseur($db); $dashboardlines[] = $board->load_board($user); } // Number of transactions to conciliate if (!empty($conf->banque->enabled) && $user->rights->banque->lire && !$user->societe_id) { include_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php'; $board = new Account($db); $dashboardlines[] = $board->load_board($user); } // Number of cheque to send if (!empty($conf->banque->enabled) && $user->rights->banque->lire && !$user->societe_id) { include_once DOL_DOCUMENT_ROOT . '/compta/paiement/cheque/class/remisecheque.class.php'; $board = new RemiseCheque($db); $dashboardlines[] = $board->load_board($user); } // Number of foundation members
*/ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.class.php'; require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/fourn.lib.php'; $langs->load('bills'); $id = GETPOST("facid", 'int'); // Security check if ($user->societe_id) { $socid = $user->societe_id; } $result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture'); /* * View */ llxHeader(); $object = new FactureFournisseur($db); $object->fetch($id); $object->info($id); $soc = new Societe($db); $soc->fetch($object->socid); $head = facturefourn_prepare_head($object); $titre = $langs->trans('SupplierInvoice'); dol_fiche_head($head, 'info', $langs->trans('SupplierInvoice'), 0, 'bill'); print '<table width="100%"><tr><td>'; dol_print_object_info($object); print '</td></tr></table>'; print '</div>'; llxFooter(); $db->close();
/** * Load an object from its id and create a new one in database * * @param int $fromid Id of object to clone * @param int $invertdetail Reverse sign of amounts for lines * @return int New id of clone */ function createFromClone($fromid, $invertdetail = 0) { global $user, $langs; $error = 0; $object = new FactureFournisseur($this->db); $object->context['createfromclone'] = 'createfromclone'; $this->db->begin(); // Load source object $object->fetch($fromid); $object->id = 0; $object->statut = self::STATUS_DRAFT; // Clear fields $object->ref_supplier = $langs->trans("CopyOf") . ' ' . $object->ref_supplier; $object->author = $user->id; $object->user_valid = ''; $object->fk_facture_source = 0; $object->date_creation = ''; $object->date_validation = ''; $object->date = ''; $object->date_echeance = ''; $object->ref_client = ''; $object->close_code = ''; $object->close_note = ''; // Loop on each line of new invoice foreach ($object->lines as $i => $line) { if (isset($object->lines[$i]->info_bits) && ($object->lines[$i]->info_bits & 0x2) == 0x2) { unset($object->lines[$i]); } } // Create clone $result = $object->create($user); // Other options if ($result < 0) { $this->error = $object->error; $error++; } if (!$error) { } unset($object->context['createfromclone']); // End if (!$error) { $this->db->commit(); return $object->id; } else { $this->db->rollback(); return -1; } }
print '<td width="100" align="center">' . $langs->trans("Date") . '</td>'; print '<td> </td>'; print '<td>' . $langs->trans("Status") . '</td>'; print '<td align="right">' . $langs->trans("Debit") . '</td>'; print '<td align="right">' . $langs->trans("Credit") . '</td>'; print '<td align="right">' . $langs->trans("Balance") . '</td>'; print '<td> </td>'; print '</tr>'; if (!$num > 0) { print '<tr><td colspan="7">' . $langs->trans("NoInvoice") . '</td></tr>'; } $solde = 0; // Boucle sur chaque facture for ($i = 0; $i < $num; $i++) { $objf = $db->fetch_object($resql); $fac = new FactureFournisseur($db); $ret = $fac->fetch($objf->facid); if ($ret < 0) { print $fac->error . "<br>"; continue; } $totalpaye = $fac->getSommePaiement(); $var = !$var; print "<tr {$bc[$var]}>"; print "<td align=\"center\">" . dol_print_date($fac->date) . "</td>\n"; print "<td><a href=\"facture/fiche.php?facid={$fac->id}\">" . img_object($langs->trans("ShowBill"), "bill") . " " . $fac->ref . "</a></td>\n"; print '<td aling="left">' . $fac->getLibStatut(2, $totalpaye) . '</td>'; print '<td align="right">' . price($fac->total_ttc) . "</td>\n"; $solde = $solde + $fac->total_ttc; print '<td align="right"> </td>'; print '<td align="right">' . price($solde) . "</td>\n";
} /* * Show result array */ $i = 0; print "<table class=\"noborder\" width=\"100%\">"; print "<tr class=\"liste_titre\">"; ///print "<td>".$langs->trans("JournalNum")."</td>"; print "<td>" . $langs->trans("Date") . "</td>"; print "<td>" . $langs->trans("Piece") . ' (' . $langs->trans("InvoiceRef") . ")</td>"; print "<td>" . $langs->trans("Account") . "</td>"; print "<t><td>" . $langs->trans("Type") . "</td><td align='right'>" . $langs->trans("Debit") . "</td><td align='right'>" . $langs->trans("Credit") . "</td>"; print "</tr>\n"; $var = true; $r = ''; $invoicestatic = new FactureFournisseur($db); $companystatic = new Fournisseur($db); foreach ($tabfac as $key => $val) { $invoicestatic->id = $key; $invoicestatic->ref = $val["ref"]; $invoicestatic->type = $val["type"]; // product foreach ($tabht[$key] as $k => $mt) { if ($mt) { print "<tr " . $bc[$var] . " >"; //print "<td>".$conf->global->COMPTA_JOURNAL_BUY."</td>"; print "<td>" . $val["date"] . "</td>"; print "<td>" . $invoicestatic->getNomUrl(1) . "</td>"; print "<td>" . $k . "</td><td>" . $langs->trans("Products") . "</td>"; print '<td align="right">' . ($mt >= 0 ? price($mt) : '') . "</td>"; print '<td align="right">' . ($mt < 0 ? price(-$mt) : '') . "</td>";
header('Location: ' . $loc); exit; } else { $db->rollback(); } } } /* * View */ $supplierstatic = new Societe($db); $invoicesupplierstatic = new FactureFournisseur($db); llxHeader(); $form = new Form($db); if ($action == 'create' || $action == 'add_paiement') { $object = new FactureFournisseur($db); $object->fetch($facid); $datefacture = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); $dateinvoice = $datefacture == '' ? empty($conf->global->MAIN_AUTOFILL_DATE) ? -1 : 0 : $datefacture; $sql = 'SELECT s.nom, s.rowid as socid,'; $sql .= ' f.rowid, f.ref, f.ref_supplier, f.amount, f.total_ttc as total'; if (!$user->rights->societe->client->voir && !$socid) { $sql .= ", sc.fk_soc, sc.fk_user "; } $sql .= ' FROM ' . MAIN_DB_PREFIX . 'societe as s, ' . MAIN_DB_PREFIX . 'facture_fourn as f'; if (!$user->rights->societe->client->voir && !$socid) { $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; } $sql .= ' WHERE f.fk_soc = s.rowid'; $sql .= ' AND f.rowid = ' . $facid; if (!$user->rights->societe->client->voir && !$socid) {
$action = GETPOST('action', 'alpha'); $confirm = GETPOST('confirm', 'alpha'); $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); $line = GETPOST('lineid', 'int'); if ($user->societe_id) { $socid = $user->societe_id; } //$result=restrictedArea($user,'produit'); $mesg = ''; /* * Actions */ // Add product to list if ($action == 'add') { $fac = new FactureFournisseur($db); $fac->fetch($id); $error = 0; for ($i = 0; $i < sizeof($fac->lines); $i++) { $object = new Labelprint($db); $object->fk_product = $fac->lines[$i]->fk_product; $object->qty = $fac->lines[$i]->qty; $result = $object->create($user); if (!$result) { $error++; } } if ($error) { $mesg = '<div class="error">' . $object->error . '</div>'; } else { $mesg = '<font class="ok">' . $langs->trans("LinesAdded") . '</font>';
$langs->load("errors"); print '<div class="error">' . $langs->trans($tmp) . '</div>'; } elseif ($tmp == 'NotConfigured') { print $langs->trans($tmp); } else { print $tmp; } print '</td>' . "\n"; print '<td align="center">'; if ($conf->global->INVOICE_SUPPLIER_ADDON_NUMBER == "{$file}") { print img_picto($langs->trans("Activated"), 'switch_on'); } else { print '<a href="' . $_SERVER["PHP_SELF"] . '?action=setmod&value=' . $file . '" alt="' . $langs->trans("Default") . '">' . img_picto($langs->trans("Disabled"), 'switch_off') . '</a>'; } print '</td>'; $invoice = new FactureFournisseur($db); $invoice->initAsSpecimen(); // Info $htmltooltip = ''; $htmltooltip .= '' . $langs->trans("Version") . ': <b>' . $module->getVersion() . '</b><br>'; $nextval = $module->getNextValue($mysoc, $invoice); if ("{$nextval}" != $langs->trans("NotAvailable")) { // Keep " on nextval $htmltooltip .= '' . $langs->trans("NextValue") . ': '; if ($nextval) { if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') { $nextval = $langs->trans($nextval); } $htmltooltip .= $nextval . '<br>'; } else { $htmltooltip .= $langs->trans($module->error) . '<br>';
$sortorder = "ASC"; } if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) { $search_ref = ""; $search_ref_supplier = ""; $search_company = ""; $search_amount_no_tax = ""; $search_amount_all_tax = ""; } /* * View */ $now = dol_now(); llxHeader('', $langs->trans("BillsSuppliersUnpaid")); $title = $langs->trans("BillsSuppliersUnpaid"); $facturestatic = new FactureFournisseur($db); $companystatic = new Societe($db); if ($user->rights->fournisseur->facture->lire) { $sql = "SELECT s.rowid as socid, s.nom as name,"; $sql .= " f.rowid, f.ref, f.ref_supplier, f.total_ht, f.total_ttc,"; $sql .= " f.datef as df, f.date_lim_reglement as datelimite, "; $sql .= " f.paye as paye, f.rowid as facid, f.fk_statut"; $sql .= " ,sum(pf.amount) as am"; if (!$user->rights->societe->client->voir && !$socid) { $sql .= ", sc.fk_soc, sc.fk_user "; } $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s"; if (!$user->rights->societe->client->voir && !$socid) { $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; } $sql .= "," . MAIN_DB_PREFIX . "facture_fourn as f";
/** * Function to build pdf onto disk * * @param FactureFournisseur $object Id of object to generate * @param Translate $outputlangs Lang output object * @param string $srctemplatepath Full path of source filename for generator using a template file * @param int $hidedetails Do not show line details * @param int $hidedesc Do not show desc * @param int $hideref Do not show ref * @return int 1=OK, 0=KO */ function write_file($object, $outputlangs = '', $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0) { global $user, $langs, $conf, $mysoc, $hookmanager; if (!is_object($outputlangs)) { $outputlangs = $langs; } // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO if (!empty($conf->global->MAIN_USE_FPDF)) { $outputlangs->charset_output = 'ISO-8859-1'; } $outputlangs->load("main"); $outputlangs->load("dict"); $outputlangs->load("companies"); $outputlangs->load("bills"); $outputlangs->load("products"); if ($conf->fournisseur->dir_output . '/facture') { $object->fetch_thirdparty(); $deja_regle = $object->getSommePaiement(); //$amount_credit_notes_included = $object->getSumCreditNotesUsed(); //$amount_deposits_included = $object->getSumDepositsUsed(); // Definition of $dir and $file if ($object->specimen) { $dir = $conf->fournisseur->facture->dir_output; $file = $dir . "/SPECIMEN.pdf"; } else { $objectref = dol_sanitizeFileName($object->ref); $objectrefsupplier = dol_sanitizeFileName($object->ref_supplier); $dir = $conf->fournisseur->facture->dir_output . '/' . get_exdir($object->id, 2) . $objectref; $file = $dir . "/" . $objectref . ".pdf"; if (!empty($conf->global->SUPPLIER_REF_IN_NAME)) { $file = $dir . "/" . $objectref . ($objectrefsupplier ? "_" . $objectrefsupplier : "") . ".pdf"; } } if (!file_exists($dir)) { if (dol_mkdir($dir) < 0) { $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); return 0; } } if (file_exists($dir)) { $nblignes = count($object->lines); $pdf = pdf_getInstance($this->format); $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance $heightforinfotot = 50; // Height reserved to output the info and total part $heightforfreetext = isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5; // Height reserved to output the free text on last page $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin) $pdf->SetAutoPageBreak(1, 0); if (class_exists('TCPDF')) { $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); } $pdf->SetFont(pdf_getPDFFont($outputlangs)); // Set path to the background PDF File if (empty($conf->global->MAIN_DISABLE_FPDI) && !empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) { $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output . '/' . $conf->global->MAIN_ADD_PDF_BACKGROUND); $tplidx = $pdf->importPage(1); } $pdf->Open(); $pagenb = 0; $pdf->SetDrawColor(128, 128, 128); $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref)); $pdf->SetSubject($outputlangs->transnoentities("Invoice")); $pdf->SetCreator("Dolibarr " . DOL_VERSION); $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref) . " " . $outputlangs->transnoentities("Order")); if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) { $pdf->SetCompression(false); } $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right // Positionne $this->atleastonediscount si on a au moins une remise for ($i = 0; $i < $nblignes; $i++) { if ($object->lines[$i]->remise_percent) { $this->atleastonediscount++; } } if (empty($this->atleastonediscount)) { $this->posxpicture += $this->postotalht - $this->posxdiscount; $this->posxtva += $this->postotalht - $this->posxdiscount; $this->posxup += $this->postotalht - $this->posxdiscount; $this->posxqty += $this->postotalht - $this->posxdiscount; $this->posxdiscount += $this->postotalht - $this->posxdiscount; //$this->postotalht; } // New page $pdf->AddPage(); if (!empty($tplidx)) { $pdf->useTemplate($tplidx); } $pagenb++; $this->_pagehead($pdf, $object, 1, $outputlangs); $pdf->SetFont('', '', $default_font_size - 1); $pdf->MultiCell(0, 3, ''); // Set interline to 3 $pdf->SetTextColor(0, 0, 0); $tab_top = 90; $tab_top_newpage = empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 : 10; $tab_height = 130; $tab_height_newpage = 150; // Affiche notes if (!empty($object->note_public)) { $tab_top = 88; $pdf->SetFont('', '', $default_font_size - 1); $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($object->note_public), 0, 1); $nexY = $pdf->GetY(); $height_note = $nexY - $tab_top; // Rect prend une longueur en 3eme param $pdf->SetDrawColor(192, 192, 192); $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1); $tab_height = $tab_height - $height_note; $tab_top = $nexY + 6; } else { $height_note = 0; } $iniY = $tab_top + 7; $curY = $tab_top + 7; $nexY = $tab_top + 7; // Loop on each lines for ($i = 0; $i < $nblignes; $i++) { $curY = $nexY; $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage $pdf->SetTextColor(0, 0, 0); $pdf->setTopMargin($tab_top_newpage); $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it. $pageposbefore = $pdf->getPage(); // Description of product line $curX = $this->posxdesc - 1; $showpricebeforepagebreak = 1; $pdf->startTransaction(); pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 3, $curX, $curY, $hideref, $hidedesc, 1); $pageposafter = $pdf->getPage(); if ($pageposafter > $pageposbefore) { $pdf->rollbackTransaction(true); $pageposafter = $pageposbefore; //print $pageposafter.'-'.$pageposbefore;exit; $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it. pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 4, $curX, $curY, $hideref, $hidedesc); $posyafter = $pdf->GetY(); if ($posyafter > $this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot)) { if ($i == $nblignes - 1) { $pdf->AddPage('', '', true); if (!empty($tplidx)) { $pdf->useTemplate($tplidx); } if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) { $this->_pagehead($pdf, $object, 0, $outputlangs); } $pdf->setPage($pageposafter + 1); } } else { // We found a page break $showpricebeforepagebreak = 0; } } else { $pdf->commitTransaction(); } $nexY = $pdf->GetY(); $pageposafter = $pdf->getPage(); $pdf->setPage($pageposbefore); $pdf->setTopMargin($this->marge_haute); $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. // We suppose that a too long description is moved completely on next page if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) { $pdf->setPage($pageposafter); $curY = $tab_top_newpage; } $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut // VAT Rate if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) { $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails); $pdf->SetXY($this->posxtva, $curY); $pdf->MultiCell($this->posxup - $this->posxtva - 1, 3, $vat_rate, 0, 'R'); } // Unit price before discount $pdf->SetXY($this->posxup, $curY); $pdf->MultiCell($this->posxqty - $this->posxup - 0.8, 3, price($object->lines[$i]->pu_ht), 0, 'R', 0); // Quantity $pdf->SetXY($this->posxqty, $curY); $pdf->MultiCell($this->posxdiscount - $this->posxqty - 0.8, 3, $object->lines[$i]->qty, 0, 'R'); // Discount on line $pdf->SetXY($this->posxdiscount, $curY); if ($object->lines[$i]->remise_percent) { $pdf->MultiCell($this->postotalht - $this->posxdiscount - 1, 3, $object->lines[$i]->remise_percent . "%", 0, 'R'); } // Total HT line $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs); $pdf->SetXY($this->postotalht, $curY); $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $total_excl_tax, 0, 'R', 0); // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva $tvaligne = $object->lines[$i]->total_tva; $localtax1ligne = $object->lines[$i]->total_localtax1; $localtax2ligne = $object->lines[$i]->total_localtax2; if (!empty($object->remise_percent)) { $tvaligne -= $tvaligne * $object->remise_percent / 100; } $vatrate = (string) $object->lines[$i]->tva_tx; $localtax1rate = (string) $object->lines[$i]->localtax1_tx; $localtax2rate = (string) $object->lines[$i]->localtax2_tx; if (($object->lines[$i]->info_bits & 0x1) == 0x1) { $vatrate .= '*'; } if (empty($this->tva[$vatrate])) { $this->tva[$vatrate] = 0; } if (empty($this->localtax1[$localtax1rate])) { $this->localtax1[$localtax1rate] = 0; } if (empty($this->localtax2[$localtax2rate])) { $this->localtax2[$localtax2rate] = 0; } $this->tva[$vatrate] += $tvaligne; $this->localtax1[$localtax1rate] += $localtax1ligne; $this->localtax2[$localtax2rate] += $localtax2ligne; // Add line if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < $nblignes - 1) { $pdf->setPage($pageposafter); $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(210, 210, 210))); //$pdf->SetDrawColor(190,190,200); $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1); $pdf->SetLineStyle(array('dash' => 0)); } $nexY += 2; // Passe espace entre les lignes // Detect if some page were added automatically and output _tableau for past pages while ($pagenb < $pageposafter) { $pdf->setPage($pagenb); if ($pagenb == 1) { $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); } else { $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); } $this->_pagefoot($pdf, $object, $outputlangs, 1); $pagenb++; $pdf->setPage($pagenb); $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) { $this->_pagehead($pdf, $object, 0, $outputlangs); } } if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) { if ($pagenb == 1) { $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); } else { $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); } $this->_pagefoot($pdf, $object, $outputlangs, 1); // New page $pdf->AddPage(); if (!empty($tplidx)) { $pdf->useTemplate($tplidx); } $pagenb++; if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) { $this->_pagehead($pdf, $object, 0, $outputlangs); } } } // Show square if ($pagenb == 1) { $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0); $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; } else { $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0); $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; } // Affiche zone totaux $posy = $this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs); $amount_credit_notes_included = 0; $amount_deposits_included = 0; if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included) { $posy = $this->_tableau_versements($pdf, $object, $posy, $outputlangs); } // Pied de page $this->_pagefoot($pdf, $object, $outputlangs); if (method_exists($pdf, 'AliasNbPages')) { $pdf->AliasNbPages(); } $pdf->Close(); $pdf->Output($file, 'F'); // Add pdfgeneration hook $hookmanager->initHooks(array('pdfgeneration')); $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs); global $action; $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks if (!empty($conf->global->MAIN_UMASK)) { @chmod($file, octdec($conf->global->MAIN_UMASK)); } return 1; // Pas d'erreur } else { $this->error = $langs->trans("ErrorCanNotCreateDir", $dir); return 0; } } else { $this->error = $langs->trans("ErrorConstantNotDefined", "SUPPLIER_OUTPUTDIR"); return 0; } $this->error = $langs->trans("ErrorUnknown"); return 0; // Erreur par defaut }
/** * Create payment in database * * @param User $user Object of creating user * @param int $closepaidinvoices 1=Also close payed invoices to paid, 0=Do nothing more * @return int id of created payment, < 0 if error */ function create($user, $closepaidinvoices = 0) { global $langs, $conf; $error = 0; // Clean parameters $this->total = 0; foreach ($this->amounts as $key => $value) { $newvalue = price2num($value, 'MT'); $this->amounts[$key] = $newvalue; $this->total += $newvalue; } $this->total = price2num($this->total); $this->db->begin(); if ($this->total != 0) { $now = dol_now(); $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . 'paiementfourn ('; $sql .= 'datec, datep, amount, fk_paiement, num_paiement, note, fk_user_author, fk_bank)'; $sql .= " VALUES ('" . $this->db->idate($now) . "',"; $sql .= " '" . $this->db->idate($this->datepaye) . "', '" . $this->total . "', " . $this->paiementid . ", '" . $this->num_paiement . "', '" . $this->db->escape($this->note) . "', " . $user->id . ", 0)"; dol_syslog("PaiementFourn::create", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . 'paiementfourn'); // Insere tableau des montants / factures foreach ($this->amounts as $key => $amount) { $facid = $key; if (is_numeric($amount) && $amount != 0) { $amount = price2num($amount); $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . 'paiementfourn_facturefourn (fk_facturefourn, fk_paiementfourn, amount)'; $sql .= ' VALUES (' . $facid . ',' . $this->id . ',\'' . $amount . '\')'; $resql = $this->db->query($sql); if ($resql) { // If we want to closed payed invoices if ($closepaidinvoices) { $invoice = new FactureFournisseur($this->db); $invoice->fetch($facid); $paiement = $invoice->getSommePaiement(); //$creditnotes=$invoice->getSumCreditNotesUsed(); $creditnotes = 0; //$deposits=$invoice->getSumDepositsUsed(); $deposits = 0; $alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT'); $remaintopay = price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits, 'MT'); if ($remaintopay == 0) { $result = $invoice->set_paid($user, '', ''); } else { dol_syslog("Remain to pay for invoice " . $facid . " not null. We do nothing."); } } } else { dol_syslog('Paiement::Create Erreur INSERT dans paiement_facture ' . $facid); $error++; } } else { dol_syslog('PaiementFourn::Create Montant non numerique', LOG_ERR); } } if (!$error) { // Call trigger $result = $this->call_trigger('PAYMENT_SUPPLIER_CREATE', $user); if ($result < 0) { $error++; } // End call triggers } } else { $this->error = $this->db->lasterror(); $error++; } } else { $this->error = "ErrorTotalIsNull"; dol_syslog('PaiementFourn::Create Error ' . $this->error, LOG_ERR); $error++; } if ($this->total != 0 && $error == 0) { $this->db->commit(); dol_syslog('PaiementFourn::Create Ok Total = ' . $this->total); return $this->id; } else { $this->db->rollback(); return -1; } }
if ($object->type == 2) { $facusing = new FactureFournisseur($db); $facusing->fetch($object->fk_facture_source); print ' (' . $langs->transnoentities("CorrectInvoice", $facusing->getNomUrl(1)) . ')'; } $facidavoir = $object->getListIdAvoirFromInvoice(); if (count($facidavoir) > 0) { print ' (' . $langs->transnoentities("InvoiceHasAvoir"); $i = 0; foreach ($facidavoir as $id) { if ($i == 0) { print ' '; } else { print ','; } $facavoir = new FactureFournisseur($db); $facavoir->fetch($id); print $facavoir->getNomUrl(1); } print ')'; } // FIXME $facidnext is not defined /* if ($facidnext > 0) { $facthatreplace=new FactureFournisseur($db); $facthatreplace->fetch($facidnext); print ' ('.$langs->transnoentities("ReplacedByInvoice",$facthatreplace->getNomUrl(1)).')'; } */ print '</td></tr>';
/** * Add a record into bank for payment with links between this bank record and invoices of payment. * All payment properties (this->amount, this->amounts, ...) must have been set first like after a call to create(). * * @param User $user Object of user making payment * @param string $mode 'payment', 'payment_supplier' * @param string $label Label to use in bank record * @param int $accountid Id of bank account to do link with * @param string $emetteur_nom Name of transmitter * @param string $emetteur_banque Name of bank * @param int $notrigger No trigger * @return int <0 if KO, bank_line_id if OK */ function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque, $notrigger = 0) { global $conf, $langs, $user; $error = 0; $bank_line_id = 0; if (!empty($conf->banque->enabled)) { if ($accountid <= 0) { $this->error = 'Bad value for parameter accountid'; dol_syslog(get_class($this) . '::addPaymentToBank ' . $this->error, LOG_ERR); return -1; } $this->db->begin(); $this->fk_account = $accountid; require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php'; dol_syslog("{$user->id},{$mode},{$label},{$this->fk_account},{$emetteur_nom},{$emetteur_banque}"); $acc = new Account($this->db); $result = $acc->fetch($this->fk_account); $totalamount = $this->amount; if (empty($totalamount)) { $totalamount = $this->total; } // For backward compatibility if ($mode == 'payment_supplier') { $totalamount = -$totalamount; } // Insert payment into llx_bank $bank_line_id = $acc->addline($this->datepaye, $this->paiementid, $label, $totalamount, $this->num_paiement, '', $user, $emetteur_nom, $emetteur_banque); // Mise a jour fk_bank dans llx_paiement // On connait ainsi le paiement qui a genere l'ecriture bancaire if ($bank_line_id > 0) { $result = $this->update_fk_bank($bank_line_id); if ($result <= 0) { $error++; dol_print_error($this->db); } // Add link 'payment', 'payment_supplier' in bank_url between payment and bank transaction if (!$error) { $url = ''; if ($mode == 'payment') { $url = DOL_URL_ROOT . '/compta/paiement/card.php?id='; } if ($mode == 'payment_supplier') { $url = DOL_URL_ROOT . '/fourn/paiement/card.php?id='; } if ($url) { $result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode); if ($result <= 0) { $error++; dol_print_error($this->db); } } } // Add link 'company' in bank_url between invoice and bank transaction (for each invoice concerned by payment) if (!$error && $label != '(WithdrawalPayment)') { $linkaddedforthirdparty = array(); foreach ($this->amounts as $key => $value) { if ($mode == 'payment') { $fac = new Facture($this->db); $fac->fetch($key); $fac->fetch_thirdparty(); if (!in_array($fac->thirdparty->id, $linkaddedforthirdparty)) { $result = $acc->add_url_line($bank_line_id, $fac->thirdparty->id, DOL_URL_ROOT . '/comm/card.php?socid=', $fac->thirdparty->name, 'company'); if ($result <= 0) { dol_syslog(get_class($this) . '::addPaymentToBank ' . $this->db->lasterror()); } $linkaddedforthirdparty[$fac->thirdparty->id] = $fac->thirdparty->id; // Mark as done for this thirdparty } } if ($mode == 'payment_supplier') { $fac = new FactureFournisseur($this->db); $fac->fetch($key); $fac->fetch_thirdparty(); if (!in_array($fac->thirdparty->id, $linkaddedforthirdparty)) { $result = $acc->add_url_line($bank_line_id, $fac->thirdparty->id, DOL_URL_ROOT . '/fourn/card.php?socid=', $fac->thirdparty->name, 'company'); if ($result <= 0) { dol_syslog(get_class($this) . '::addPaymentToBank ' . $this->db->lasterror()); } $linkaddedforthirdparty[$fac->thirdparty->id] = $fac->thirdparty->id; // Mark as done for this thirdparty } } } } if (!$error && !$notrigger) { // Appel des triggers $result = $this->call_trigger('PAYMENT_ADD_TO_BANK', $user); if ($result < 0) { $error++; } // Fin appel triggers } } else { $this->error = $acc->error; $error++; } if (!$error) { $this->db->commit(); } else { $this->db->rollback(); } } if (!$error) { return $bank_line_id; } else { return -1; } }
if (!$resql) { setEventMessage($db->lasterror(), 'errors'); } } /* * View */ llxHeader("", "", "FicheVentilation"); if ($cancel == $langs->trans("Cancel")) { $action = ''; } /* * Create */ $form = new Form($db); $facturefournisseur_static = new FactureFournisseur($db); $formventilation = new FormVentilation($db); if ($_GET["id"]) { $sql = "SELECT f.ref as facnumber, f.rowid as facid, l.fk_product, l.description, l.rowid, l.fk_code_ventilation, "; $sql .= " p.rowid as product_id, p.ref as product_ref, p.label as product_label"; $sql .= ", aa.account_number, aa.label"; $sql .= " FROM " . MAIN_DB_PREFIX . "facture_fourn_det as l"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = l.fk_product"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accountingaccount as aa ON l.fk_code_ventilation = aa.rowid"; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "facture_fourn as f ON f.rowid = l.fk_facture_fourn "; $sql .= " WHERE f.fk_statut > 0 AND l.rowid = " . $id; if (!empty($conf->multicompany->enabled)) { $sql .= " AND f.entity = '" . $conf->entity . "'"; } $result = $db->query($sql); if ($result) {
$id = isset($_GET["account"]) ? $_GET["account"] : (isset($_GET["ref"]) ? $_GET["ref"] : ''); } $fieldid = isset($_GET["ref"]) ? 'ref' : 'rowid'; if ($user->societe_id) { $socid = $user->societe_id; } $result = restrictedArea($user, 'banque', $id, 'bank_account&bank_account', '', '', $fieldid); $vline = isset($_GET["vline"]) ? $_GET["vline"] : $_POST["vline"]; $page = isset($_GET["page"]) ? $_GET["page"] : 0; /* * View */ llxHeader(); $societestatic = new Societe($db); $facturestatic = new Facture($db); $facturefournstatic = new FactureFournisseur($db); $socialcontribstatic = new ChargeSociales($db); $form = new Form($db); if ($_REQUEST["account"] || $_REQUEST["ref"]) { if ($vline) { $viewline = $vline; } else { $viewline = 20; } $acct = new Account($db); if ($_GET["account"]) { $result = $acct->fetch($_GET["account"]); } if ($_GET["ref"]) { $result = $acct->fetch(0, $_GET["ref"]); $_GET["account"] = $acct->id;
$i++; } $db->free($resql); if ($num > 0) { print "</table>"; } } else { dol_print_error($db); } } /* * Last invoices */ $MAXLIST = 5; $langs->load('bills'); $facturestatic = new FactureFournisseur($db); if ($user->rights->fournisseur->facture->lire) { // TODO move to DAO class $sql = 'SELECT f.rowid,f.libelle,f.facnumber,f.fk_statut,f.datef as df,f.total_ttc as amount,f.paye,'; $sql .= ' SUM(pf.amount) as am'; $sql .= ' FROM ' . MAIN_DB_PREFIX . 'facture_fourn as f'; $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'paiementfourn_facturefourn as pf ON f.rowid=pf.fk_facturefourn'; $sql .= ' WHERE f.fk_soc = ' . $object->id; $sql .= ' GROUP BY f.rowid,f.libelle,f.facnumber,f.fk_statut,f.datef,f.total_ttc,f.paye'; $sql .= ' ORDER BY f.datef DESC'; $resql = $db->query($sql); if ($resql) { $i = 0; $num = $db->num_rows($resql); if ($num > 0) { print '<table class="noborder" width="100%">';
if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) { $colspan++; } print '<tr ' . $bc[$var] . '><td colspan="' . $colspan . '">' . $langs->trans("NoInvoice") . '</td></tr>'; } print '</table><br>'; $db->free($resql); } else { dol_print_error($db); } } /* * Unpayed supplier invoices */ if (!empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) { $facstatic = new FactureFournisseur($db); $sql = "SELECT ff.rowid, ff.ref, ff.fk_statut, ff.libelle, ff.total_ht, ff.total_ttc, ff.paye,"; $sql .= " s.nom, s.rowid as socid,"; $sql .= " sum(pf.amount) as am"; $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s, " . MAIN_DB_PREFIX . "facture_fourn as ff"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as pf on ff.rowid=pf.fk_facturefourn"; if (!$user->rights->societe->client->voir && !$socid) { $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; } $sql .= " WHERE s.rowid = ff.fk_soc"; $sql .= " AND ff.entity = " . $conf->entity; $sql .= " AND ff.paye = 0"; $sql .= " AND ff.fk_statut = 1"; if (!$user->rights->societe->client->voir && !$socid) { $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user->id; }
/** * testFactureFournisseurDelete * * @param int $id Id of supplier invoice * @return void * * @depends testFactureFournisseurOther * The depends says test is run only if previous is ok */ public function testFactureFournisseurDelete($id) { global $conf, $user, $langs, $db; $conf = $this->savconf; $user = $this->savuser; $langs = $this->savlangs; $db = $this->savdb; $localobject = new FactureFournisseur($this->savdb); $result = $localobject->fetch($id); $result = $localobject->delete($id); print __METHOD__ . " id=" . $id . " result=" . $result . "\n"; $this->assertLessThan($result, 0); return $result; }
$result = restrictedArea($user, 'tax', '', '', 'charges'); /* * View */ $morequerystring = ''; $listofparams = array('date_startmonth', 'date_startyear', 'date_startday', 'date_endmonth', 'date_endyear', 'date_endday'); foreach ($listofparams as $param) { if (GETPOST($param) != '') { $morequerystring .= ($morequerystring ? '&' : '') . $param . '=' . GETPOST($param); } } llxHeader('', '', '', '', 0, 0, '', '', $morequerystring); $form = new Form($db); $company_static = new Societe($db); $invoice_customer = new Facture($db); $invoice_supplier = new FactureFournisseur($db); $product_static = new Product($db); $payment_static = new Paiement($db); $paymentfourn_static = new PaiementFourn($db); //print load_fiche_titre($langs->trans("VAT"),""); //$fsearch.='<br>'; $fsearch .= ' <input type="hidden" name="year" value="' . $year . '">'; $fsearch .= ' <input type="hidden" name="modetax" value="' . $modetax . '">'; //$fsearch.=' '.$langs->trans("SalesTurnoverMinimum").': '; //$fsearch.=' <input type="text" name="min" value="'.$min.'">'; // Affiche en-tete du rapport if ($modetax == 1) { $nom = $langs->trans("VATReportByQuartersInDueDebtMode"); $calcmode = $langs->trans("CalcModeVATDebt"); $calcmode .= '<br>(' . $langs->trans("TaxModuleSetupToModifyRules", DOL_URL_ROOT . '/admin/taxes.php') . ')'; $period = $form->select_date($date_start, 'date_start', 0, 0, 0, '', 1, 0, 1) . ' - ' . $form->select_date($date_end, 'date_end', 0, 0, 0, '', 1, 0, 1);
$html = new Form($db); $formcompany = new FormCompany($db); $contactstatic=new Contact($db); $userstatic=new User($db); /* *************************************************************************** */ /* */ /* Mode vue et edition */ /* */ /* *************************************************************************** */ if (isset($mesg)) print $mesg; $id = $_GET["facid"]; if ($id > 0) { $facture = new FactureFournisseur($db); if ($facture->fetch($_GET['facid'], $user->societe_id) > 0) { $facture->fetch_thirdparty(); $head = facturefourn_prepare_head($facture); dol_fiche_head($head, 'contact', $langs->trans('SupplierInvoice'), 0, 'bill'); /* * Facture synthese pour rappel */ print '<table class="border" width="100%">'; // Reference du facture print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td colspan="3">';