예제 #1
0
        Header('Location: ' . $loc);
        exit;
    } else {
        $db->rollback();
    }
}
/*
 * View
 */
llxHeader();
$html = new Form($db);
if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paiement') {
    $facture = new Facture($db);
    $result = $facture->fetch($facid);
    if ($result >= 0) {
        $facture->fetch_thirdparty();
        $title = '';
        if ($facture->type != 2) {
            $title .= $langs->trans("EnterPaymentReceivedFromCustomer");
        }
        if ($facture->type == 2) {
            $title .= $langs->trans("EnterPaymentDueToCustomer");
        }
        print_fiche_titre($title);
        dol_htmloutput_errors($errmsg);
        // Bouchon
        if ($facture->type == 2) {
            print $langs->trans("FeatureNotYetAvailable");
            llxFooter();
            exit;
        }
예제 #2
0
 /**
  *      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;
     }
 }
예제 #3
0
    }
    print '<input type="hidden" name="email" value="' . $order->thirdparty->email . '">' . "\n";
    print '<input type="hidden" name="desc" value="' . $langs->trans("Order") . ' ' . $order->ref . '">' . "\n";
}
// Payment on customer invoice
if (GETPOST("source") == 'invoice' && $valid) {
    $found = true;
    $langs->load("bills");
    require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
    $invoice = new Facture($db);
    $result = $invoice->fetch('', $ref);
    if ($result < 0) {
        $mesg = $invoice->error;
        $error++;
    } else {
        $result = $invoice->fetch_thirdparty($invoice->socid);
    }
    $amount = price2num($invoice->total_ttc - $invoice->getSommePaiement());
    if (GETPOST("amount", 'int')) {
        $amount = GETPOST("amount", 'int');
    }
    $amount = price2num($amount);
    $fulltag = 'INV=' . $invoice->ref . '.CUS=' . $invoice->thirdparty->id;
    //$fulltag.='.NAM='.strtr($invoice->thirdparty->name,"-"," ");
    if (!empty($TAG)) {
        $tag = $TAG;
        $fulltag .= '.TAG=' . $TAG;
    }
    $fulltag = dol_string_unaccent($fulltag);
    // Creditor
    $var = !$var;
예제 #4
0
 print load_fiche_titre($langs->trans("CreateRepeatableInvoice"), '', 'title_accountancy.png');
 $object = new Facture($db);
 // Source invoice
 $product_static = new Product($db);
 if ($object->fetch($id) > 0) {
     print '<form action="fiche-rec.php" method="post">';
     print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
     print '<input type="hidden" name="action" value="add">';
     print '<input type="hidden" name="facid" value="' . $object->id . '">';
     dol_fiche_head();
     $rowspan = 4;
     if (!empty($conf->projet->enabled) && $object->fk_project > 0) {
         $rowspan++;
     }
     print '<table class="border" width="100%">';
     $object->fetch_thirdparty();
     // Third party
     print '<tr><td>' . $langs->trans("Customer") . '</td><td>' . $object->client->getNomUrl(1, 'customer') . '</td>';
     print '<td>';
     print $langs->trans("Comment");
     print '</td></tr>';
     // Title
     print '<tr><td class="fieldrequired">' . $langs->trans("Title") . '</td><td>';
     print '<input class="flat" type="text" name="titre" size="24" value="' . $_POST["titre"] . '">';
     print '</td>';
     // Note
     print '<td rowspan="' . $rowspan . '" valign="top">';
     print '<textarea class="flat" name="note_private" wrap="soft" cols="60" rows="' . ROWS_4 . '"></textarea>';
     print '</td></tr>';
     // Author
     print "<tr><td>" . $langs->trans("Author") . "</td><td>" . $user->getFullName($langs) . "</td></tr>";
 /**
  *
  * Add facture Payment
  *
  * @param array $aryTicket	Ticket data array
  */
 private function addPaymentFac($aryTicket)
 {
     global $db, $langs, $conf;
     require_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php';
     $now = dol_now();
     $userstatic = new User($db);
     $error = 0;
     if (!$aryTicket['employeeId']) {
         $employee = $_SESSION['uid'];
     } else {
         $employee = $aryTicket['employeeId'];
     }
     $userstatic->fetch($employee);
     $max_ite = 3;
     if ($aryTicket['convertDis']) {
         require_once DOL_DOCUMENT_ROOT . '/core/class/discount.class.php';
         $object = new Facture($db);
         $object->fetch($aryTicket['id']);
         $object->fetch_thirdparty();
         // Check if there is already a discount (protection to avoid duplicate creation when resubmit post)
         $discountcheck = new DiscountAbsolute($db);
         $result = $discountcheck->fetch(0, $object->id);
         $canconvert = 0;
         if ($object->type == Facture::TYPE_CREDIT_NOTE && $object->paye == 0 && empty($discountcheck->id)) {
             $canconvert = 1;
         }
         // we can convert credit note into discount if credit note is not payed back and not already converted and amount of payment is 0 (see real condition into condition used to show button converttoreduc)
         if ($canconvert) {
             $db->begin();
             // Boucle sur chaque taux de tva
             $i = 0;
             foreach ($object->lines as $line) {
                 $amount_ht[$line->tva_tx] += $line->total_ht;
                 $amount_tva[$line->tva_tx] += $line->total_tva;
                 $amount_ttc[$line->tva_tx] += $line->total_ttc;
                 $i++;
             }
             // Insert one discount by VAT rate category
             $discount = new DiscountAbsolute($db);
             if ($object->type == Facture::TYPE_CREDIT_NOTE) {
                 $discount->description = $langs->trans('DiscountOf', $object->ref);
             }
             $discount->tva_tx = abs($object->total_ttc);
             $discount->fk_soc = $object->socid;
             $discount->fk_facture_source = $object->id;
             $error = 0;
             foreach ($amount_ht as $tva_tx => $xxx) {
                 $discount->amount_ht = abs($amount_ht[$tva_tx]);
                 $discount->amount_tva = abs($amount_tva[$tva_tx]);
                 $discount->amount_ttc = abs($amount_ttc[$tva_tx]);
                 $discount->tva_tx = abs($tva_tx);
                 $paiement_id = $discount->create($userstatic);
                 if ($paiement_id < 0) {
                     $error++;
                     break;
                 }
             }
             if (empty($error)) {
                 // Classe facture
                 $paiement_id = $object->set_paid($user);
                 if ($result >= 0) {
                     //$mesgs[]='OK'.$discount->id;
                     $db->commit();
                 } else {
                     $db->rollback();
                 }
             } else {
                 $db->rollback();
             }
         }
     } else {
         if ($aryTicket['type'] == 1) {
             if ($aryTicket['total'] > $aryTicket['customerpay'] && $aryTicket['difpayment'] == 0) {
                 dol_include_once('/rewards/class/rewards.class.php');
                 $reward = new Rewards($db);
                 $facture = new Facture($db);
                 $facture->fetch($aryTicket['id']);
                 $modepay[4] = dol_getIdFromCode($db, 'PNT', 'c_paiement');
                 $amount[4] = $aryTicket['total'] - $aryTicket['customerpay'];
                 $result = $reward->create($facture, price2num($amount[4]) / $conf->global->REWARDS_DISCOUNT);
                 $max_ite++;
                 $amount[4] = $amount[4] * -1;
                 //TODO tot molt bonico, pero que pasa si no gaste punts?
             }
             $aryTicket['total'] = $aryTicket['total'] * -1;
             $aryTicket['customerpay1'] = $aryTicket['customerpay1'] * -1;
             $aryTicket['customerpay2'] = $aryTicket['customerpay2'] * -1;
             $aryTicket['customerpay3'] = $aryTicket['customerpay3'] * -1;
         }
         $cash = new Cash($db);
         $terminal = $_SESSION['TERMINAL_ID'];
         $cash->fetch($terminal);
         if ($aryTicket['customerpay1'] != 0) {
             $bankaccountid[1] = $cash->fk_paycash;
             $modepay[1] = $cash->fk_modepaycash;
             $amount[1] = $aryTicket['customerpay1'] + ($aryTicket['difpayment'] < 0 ? $aryTicket['difpayment'] : 0);
         }
         if ($aryTicket['customerpay2'] != 0) {
             $bankaccountid[2] = $cash->fk_paybank;
             $modepay[2] = $cash->fk_modepaybank;
             $amount[2] = $aryTicket['customerpay2'];
         }
         if ($aryTicket['customerpay3'] != 0) {
             $bankaccountid[3] = $cash->fk_paybank_extra;
             $modepay[3] = $cash->fk_modepaybank_extra;
             $amount[3] = $aryTicket['customerpay3'];
         }
         //Añadir el posible pago de puntos
         if ($aryTicket['points'] > 0) {
             dol_include_once('/rewards/class/rewards.class.php');
             $reward = new Rewards($db);
             $facture = new Facture($db);
             $facture->fetch($aryTicket['id']);
             $res = $reward->usePoints($facture, $aryTicket['points']);
         }
         $i = 1;
         $payment = new Paiement($db);
         while ($i <= $max_ite) {
             $payment->datepaye = $now;
             $payment->bank_account = $bankaccountid[$i];
             $payment->amounts[$aryTicket['id']] = $amount[$i];
             $payment->note = $langs->trans("Payment") . ' ' . $langs->trans("Facture") . ' ' . $aryTicket['ref'];
             $payment->paiementid = $modepay[$i];
             $payment->num_paiement = '';
             if ($amount[$i] != 0) {
                 $paiement_id = $payment->create($userstatic, 1);
                 if ($paiement_id > 0) {
                     if ($payment->paiementid != dol_getIdFromCode($db, 'PNT', 'c_paiement')) {
                         $result = $payment->addPaymentToBank($userstatic, 'payment', '(CustomerFacturePayment)', $bankaccountid[$i], $aryTicket['customerId'], '', '');
                         if ($result < 0) {
                             $error++;
                         }
                     }
                 } else {
                     $error++;
                 }
             }
             $i++;
         }
     }
     if ($error > 0) {
         return -1;
     } else {
         return 1;
     }
     //$paiement_id;
 }
 function _showLCR($pdf, $object, $outputlangs, &$TtoGenerate)
 {
     global $db, $conf;
     //Gestion LCR /////////////////////////////////////////////////////////////////////
     $pdf->AddPage();
     $posy = 50;
     $pdf->SetDrawColor(0, 0, 0);
     $default_font_size = pdf_getPDFFontSize($outputlangs);
     $nb_facture = count($TtoGenerate);
     foreach ($TtoGenerate as $ii => $ref_piece) {
         $f = new Facture($db);
         $f->fetch('', $ref_piece);
         $f->fetch_thirdparty();
         $object =& $f;
         if (!empty($conf->global->LCR_USE_REST_TO_PAY)) {
             $deja_regle = $object->getSommePaiement();
             $creditnoteamount = $object->getSumCreditNotesUsed();
             $depositsamount = $object->getSumDepositsUsed();
             $resteapayer = price2num($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
         } else {
             $resteapayer = price2num($object->total_ttc);
         }
         // ENTETE
         if (!empty($conf->global->LCR_GENERATE_ONE_PER_PAGE_WiTH_ADDRESS)) {
             $this->_pagehead($pdf, $object, 1, $outputlangs);
             $curx = $this->marge_gauche;
             $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)
             $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 10;
             $cury = $bottomlasttab;
             $pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(200, 200, 200)));
             $pdf->Line($curx, $cury - 11, $this->page_largeur - $this->marge_droite, $cury - 11);
             $pdf->SetLineStyle(array('dash' => 0, 'color' => array(0, 0, 0)));
         } else {
             $curx = $this->marge_gauche;
             $cury = $posy - 30;
         }
         $pdf->SetFont('', '', $default_font_size - 1);
         $pdf->writeHTMLCell(53, 20, 10, $cury - 8, $outputlangs->convToOutputCharset('MERCI DE NOUS RETOURNER LA PRESENTE TRAITE SOUS 8 JOURS.'), 0, 1, false, true, 'J', true);
         $pdf->SetFont('', '', $default_font_size - 3);
         $pdf->writeHTMLCell(40, 20, 70, $cury - 8, $outputlangs->convToOutputCharset('Contre cette LETTRE DE CHANGE STIPULEE SANS FRAIS'), 0, 1, false, true, 'J', true);
         $pdf->writeHTMLCell(40, 20, 70, $cury - 3, $outputlangs->convToOutputCharset('Veuillez payer la somme indiquée ci_dessous à l\'ordre de'), 0, 1, false, true, 'J', true);
         $pdf->SetFont('', '', $default_font_size - 2);
         $pdf->writeHTMLCell(20, 20, 115, $cury - 8, $outputlangs->convToOutputCharset($conf->global->MAIN_INFO_SOCIETE_NOM), 0, 1, false, true, 'J', true);
         $pdf->writeHTMLCell(40, 20, 115, $cury - 5, $outputlangs->convToOutputCharset($conf->global->MAIN_INFO_SOCIETE_ADDRESS), 0, 1, false, true, 'J', true);
         $pdf->writeHTMLCell(40, 20, 115, $cury + 1, $outputlangs->convToOutputCharset($conf->global->MAIN_INFO_SOCIETE_ZIP . ' ' . $conf->global->MAIN_INFO_SOCIETE_TOWN), 0, 1, false, true, 'J', true);
         //Affichage code monnaie
         $pdf->SetXY(180, $cury + 1);
         $pdf->SetFont(pdf_getPDFFont($outputlangs), '', 7);
         $pdf->Cell(18, 0, "Code Monnaie", 0, 1, C);
         $pdf->SetXY(180, $cury + 5);
         $pdf->SetFont(pdf_getPDFFont($outputlangs), 'B', 14);
         $pdf->Cell(18, 0, $outputlangs->trans($conf->currency), 0, 0, C);
         //Affichage lieu / date
         //$town = !empty($this->emetteur->town) ? $this->emetteur->town : $this->emetteur->ville;
         $town = $conf->global->MAIN_INFO_SOCIETE_TOWN;
         $cury += 5;
         $pdf->SetXY(30, $cury);
         $pdf->SetFont(pdf_getPDFFont($outputlangs), 'B', 8);
         $pdf->Cell(15, 0, "A " . $outputlangs->convToOutputCharset($town) . ", le", 0, 1, 'R');
         // jolie fleche ...
         $curx = 43;
         $cury += 2;
         $largeur_cadre = 5;
         $pdf->Line($curx + $largeur_cadre, $cury, $curx + $largeur_cadre + 5, $cury);
         $pdf->Line($curx + $largeur_cadre + 5, $cury, $curx + $largeur_cadre + 5, $cury + 2);
         $pdf->Line($curx + $largeur_cadre + 4, $cury + 2, $curx + $largeur_cadre + 6, $cury + 2);
         $pdf->Line($curx + $largeur_cadre + 4, $cury + 2, $curx + $largeur_cadre + 5, $cury + 3);
         $pdf->Line($curx + $largeur_cadre + 6, $cury + 2, $curx + $largeur_cadre + 5, $cury + 3);
         // fin jolie fleche
         //Affichage toute la ligne qui commence par "montant pour controle" ...
         $curx = $this->marge_gauche;
         $cury += 5;
         $hauteur_cadre = 8;
         $largeur_cadre = 27;
         $pdf->SetXY($curx, $cury);
         $pdf->SetFont(pdf_getPDFFont($outputlangs), '', 7);
         $pdf->Cell($largeur_cadre, 0, "Montant pour contrôle", 0, 0, C);
         $pdf->Line($curx, $cury, $curx, $cury + $hauteur_cadre);
         $pdf->Line($curx, $cury + $hauteur_cadre, $curx + $largeur_cadre, $cury + $hauteur_cadre);
         $pdf->Line($curx + $largeur_cadre, $cury, $curx + $largeur_cadre, $cury + $hauteur_cadre);
         $pdf->SetXY($curx, $cury + 4);
         $pdf->SetFont(pdf_getPDFFont($outputlangs), 'B', 8);
         $pdf->Cell($largeur_cadre, 0, price($resteapayer), 0, 0, C);
         $curx = $curx + $largeur_cadre + 5;
         $hauteur_cadre = 8;
         $largeur_cadre = 25;
         $pdf->SetXY($curx, $cury);
         $pdf->SetFont(pdf_getPDFFont($outputlangs), '', 7);
         $pdf->Cell($largeur_cadre, 0, "Date de création", 0, 0, C);
         $pdf->Line($curx, $cury, $curx, $cury + $hauteur_cadre);
         $pdf->Line($curx, $cury + $hauteur_cadre, $curx + $largeur_cadre, $cury + $hauteur_cadre);
         $pdf->Line($curx + $largeur_cadre, $cury, $curx + $largeur_cadre, $cury + $hauteur_cadre);
         $pdf->SetXY($curx, $cury + 4);
         $pdf->SetFont(pdf_getPDFFont($outputlangs), 'B', 8);
         $pdf->Cell($largeur_cadre, 0, dol_print_date($object->date, "day", false, $outpulangs), 0, 0, C);
         $curx = $curx + $largeur_cadre + 5;
         $hauteur_cadre = 8;
         $largeur_cadre = 25;
         $pdf->SetXY($curx, $cury);
         $pdf->SetFont(pdf_getPDFFont($outputlangs), '', 7);
         $pdf->Cell($largeur_cadre, 0, "Echéance", 0, 0, C);
         $pdf->Line($curx, $cury, $curx, $cury + $hauteur_cadre);
         $pdf->Line($curx, $cury + $hauteur_cadre, $curx + $largeur_cadre, $cury + $hauteur_cadre);
         $pdf->Line($curx + $largeur_cadre, $cury, $curx + $largeur_cadre, $cury + $hauteur_cadre);
         $pdf->SetXY($curx, $cury + 4);
         $pdf->SetFont(pdf_getPDFFont($outputlangs), 'B', 8);
         $pdf->Cell($largeur_cadre, 0, dol_print_date($object->date_lim_reglement, "day"), 0, 0, C);
         $curx = $curx + $largeur_cadre + 5;
         $hauteur_cadre = 8;
         $largeur_cadre = 75;
         $pdf->SetXY($curx, $cury - 1);
         $pdf->SetFont(pdf_getPDFFont($outputlangs), '', 7);
         $pdf->Cell($largeur_cadre, 0, "LCR Seulement", 0, 0, C);
         $largeurportioncadre = 30;
         $pdf->Line($curx, $cury, $curx, $cury + $hauteur_cadre);
         $pdf->Line($curx, $cury + $hauteur_cadre, $curx + $largeurportioncadre, $cury + $hauteur_cadre);
         $curx += $largeurportioncadre;
         $pdf->Line($curx, $cury + 2, $curx, $cury + $hauteur_cadre);
         $curx += 10;
         $largeurportioncadre = 6;
         $pdf->Line($curx, $cury + 2, $curx, $cury + $hauteur_cadre);
         $pdf->Line($curx, $cury + $hauteur_cadre, $curx + $largeurportioncadre, $cury + $hauteur_cadre);
         $curx += $largeurportioncadre;
         $pdf->Line($curx, $cury + 2, $curx, $cury + $hauteur_cadre);
         $curx += 3;
         $largeurportioncadre = 6;
         $pdf->Line($curx, $cury + 2, $curx, $cury + $hauteur_cadre);
         $pdf->Line($curx, $cury + $hauteur_cadre, $curx + $largeurportioncadre, $cury + $hauteur_cadre);
         $curx += $largeurportioncadre;
         $pdf->Line($curx, $cury + 2, $curx, $cury + $hauteur_cadre);
         $curx += 3;
         $largeurportioncadre = 12;
         $pdf->Line($curx, $cury + 2, $curx, $cury + $hauteur_cadre);
         $pdf->Line($curx, $cury + $hauteur_cadre, $curx + $largeurportioncadre, $cury + $hauteur_cadre);
         $curx += $largeurportioncadre;
         $pdf->Line($curx, $cury, $curx, $cury + $hauteur_cadre);
         $curx += 3;
         $hauteur_cadre = 8;
         $largeur_cadre = 30;
         $pdf->SetXY($curx, $cury);
         $pdf->SetFont(pdf_getPDFFont($outputlangs), '', 7);
         $pdf->Cell($largeur_cadre, 0, "Montant", 0, 0, C);
         $pdf->Line($curx, $cury, $curx, $cury + $hauteur_cadre);
         $pdf->Line($curx, $cury + $hauteur_cadre, $curx + $largeur_cadre, $cury + $hauteur_cadre);
         $pdf->Line($curx + $largeur_cadre, $cury, $curx + $largeur_cadre, $cury + $hauteur_cadre);
         $pdf->SetXY($curx, $cury + 4);
         $pdf->SetFont(pdf_getPDFFont($outputlangs), 'B', 8);
         $pdf->Cell($largeur_cadre, 0, price($resteapayer), 0, 0, C);
         $cury = $cury + $hauteur_cadre + 3;
         $curx = 20;
         $hauteur_cadre = 6;
         $largeur_cadre = 70;
         $pdf->Line($curx, $cury, $curx, $cury + $hauteur_cadre);
         $pdf->Line($curx, $cury, $curx + $largeur_cadre / 5, $cury);
         $pdf->Line($curx, $cury + $hauteur_cadre, $curx + $largeur_cadre / 5, $cury + $hauteur_cadre);
         $pdf->Line($curx + $largeur_cadre, $cury, $curx + $largeur_cadre, $cury + $hauteur_cadre);
         $pdf->Line($curx + $largeur_cadre, $cury, $curx + $largeur_cadre * 4 / 5, $cury);
         $pdf->Line($curx + $largeur_cadre, $cury + $hauteur_cadre, $curx + $largeur_cadre * 4 / 5, $cury + $hauteur_cadre);
         $pdf->SetXY($curx, $cury + 1.5);
         $pdf->SetFont(pdf_getPDFFont($outputlangs), 'B', 8);
         $pdf->Cell($largeur_cadre, 1, $outputlangs->convToOutputCharset($object->ref), 0, 0, C);
         $curx = $curx + $largeur_cadre + 15;
         $largeur_cadre = 50;
         $pdf->Line($curx, $cury, $curx, $cury + $hauteur_cadre);
         $pdf->Line($curx, $cury, $curx + $largeur_cadre / 5, $cury);
         $pdf->Line($curx, $cury + $hauteur_cadre, $curx + $largeur_cadre / 5, $cury + $hauteur_cadre);
         $pdf->Line($curx + $largeur_cadre, $cury, $curx + $largeur_cadre, $cury + $hauteur_cadre);
         $pdf->Line($curx + $largeur_cadre, $cury, $curx + $largeur_cadre * 4 / 5, $cury);
         $pdf->Line($curx + $largeur_cadre, $cury + $hauteur_cadre, $curx + $largeur_cadre * 4 / 5, $cury + $hauteur_cadre);
         $pdf->SetXY($curx, $cury + 2);
         $pdf->SetFont(pdf_getPDFFont($outputlangs), 'B', 8);
         // MB leave blank
         //$pdf->Cell($largeur_cadre, 0, "Réf ",0,0,C);
         $curx = $curx + $largeur_cadre + 10;
         $largeur_cadre = 30;
         $pdf->Line($curx, $cury, $curx, $cury + $hauteur_cadre);
         $pdf->Line($curx, $cury, $curx + $largeur_cadre / 5, $cury);
         $pdf->Line($curx, $cury + $hauteur_cadre, $curx + $largeur_cadre / 5, $cury + $hauteur_cadre);
         $pdf->Line($curx + $largeur_cadre, $cury, $curx + $largeur_cadre, $cury + $hauteur_cadre);
         $pdf->Line($curx + $largeur_cadre, $cury, $curx + $largeur_cadre * 4 / 5, $cury);
         $pdf->Line($curx + $largeur_cadre, $cury + $hauteur_cadre, $curx + $largeur_cadre * 4 / 5, $cury + $hauteur_cadre);
         $pdf->SetXY($curx, $cury + 2);
         $pdf->SetFont(pdf_getPDFFont($outputlangs), 'B', 8);
         // MB leave blank
         //$pdf->Cell($largeur_cadre, 0, "R�f ",0,0,C);
         // RIB client
         $cury = $cury + $hauteur_cadre + 3;
         $largeur_cadre = 70;
         $hauteur_cadre = 6;
         $sql = "SELECT rib.fk_soc, rib.domiciliation, rib.code_banque, rib.code_guichet, rib.number, rib.cle_rib";
         $sql .= " FROM " . MAIN_DB_PREFIX . "societe_rib as rib";
         $sql .= " WHERE rib.fk_soc = " . $object->client->id;
         $sql .= ' ORDER BY default_rib DESC LIMIT 1';
         // On veux en priorité le RIB par défaut si jamais on tombe sur le cas de +sieurs RIB mais pas de default alors on en prend qu'un
         $resql = $this->db->query($sql);
         if ($resql) {
             $num = $this->db->num_rows($resql);
             $i = 0;
             while ($i <= $num) {
                 $cpt = $this->db->fetch_object($resql);
                 $curx = $this->marge_gauche;
                 $pdf->Line($curx, $cury, $curx + $largeur_cadre, $cury);
                 $pdf->Line($curx, $cury, $curx, $cury + $hauteur_cadre);
                 $pdf->Line($curx + 22, $cury, $curx + 22, $cury + $hauteur_cadre - 2);
                 $pdf->Line($curx + 35, $cury, $curx + 35, $cury + $hauteur_cadre - 2);
                 $pdf->Line($curx + 60, $cury, $curx + 60, $cury + $hauteur_cadre - 2);
                 $pdf->Line($curx + 70, $cury, $curx + 70, $cury + $hauteur_cadre);
                 $pdf->SetXY($curx + 5, $cury + $hauteur_cadre - 4);
                 $pdf->SetFont(pdf_getPDFFont($outputlangs), 'B', 8);
                 if ($cpt->code_banque && $cpt->code_guichet && $cpt->number && $cpt->cle_rib) {
                     $pdf->Cell($largeur_cadre, 1, $cpt->code_banque . "             " . $cpt->code_guichet . "         " . $cpt->number . "        " . $cpt->cle_rib, 0, 0, L);
                 }
                 $pdf->SetXY($curx, $cury + $hauteur_cadre - 1);
                 $pdf->SetFont(pdf_getPDFFont($outputlangs), '', 6);
                 $pdf->Cell($largeur_cadre, 1, "Code établissement    Code guichet           N° de compte            Cl RIB", 0, 0, L);
                 $curx = 150;
                 $largeur_cadre = 55;
                 $pdf->SetXY($curx, $cury - 1);
                 $pdf->SetFont(pdf_getPDFFont($outputlangs), '', 6);
                 $pdf->Cell($largeur_cadre, 1, "Domiciliation bancaire", 0, 0, C);
                 $pdf->SetXY($curx, $cury + 2);
                 $pdf->SetFont(pdf_getPDFFont($outputlangs), 'B', 8);
                 if ($cpt->domiciliation) {
                     $pdf->Cell($largeur_cadre, 5, $outputlangs->convToOutputCharset($cpt->domiciliation), 1, 0, C);
                 }
                 $i++;
             }
         }
         //
         $cury = $cury + $hauteur_cadre + 3;
         $curx = $this->marge_gauche;
         $largeur_cadre = 20;
         $pdf->SetXY($curx, $cury);
         $pdf->SetFont(pdf_getPDFFont($outputlangs), '', 6);
         $pdf->Cell($largeur_cadre, 1, "Acceptation ou aval", 0, 0, L);
         // jolie fl�che ...
         $cury += 2;
         $pdf->Line($curx + $largeur_cadre, $cury, $curx + $largeur_cadre + 5, $cury);
         $pdf->Line($curx + $largeur_cadre + 5, $cury, $curx + $largeur_cadre + 5, $cury + 2);
         $pdf->Line($curx + $largeur_cadre + 4, $cury + 2, $curx + $largeur_cadre + 6, $cury + 2);
         $pdf->Line($curx + $largeur_cadre + 4, $cury + 2, $curx + $largeur_cadre + 5, $cury + 3);
         $pdf->Line($curx + $largeur_cadre + 6, $cury + 2, $curx + $largeur_cadre + 5, $cury + 3);
         // fin jolie fl�che
         //Coordonn�es du tir�
         $curx += 50;
         $largeur_cadre = 20;
         $hauteur_cadre = 6;
         $pdf->SetXY($curx, $cury);
         $pdf->SetFont(pdf_getPDFFont($outputlangs), '', 6);
         $pdf->MultiCell($largeur_cadre, $hauteur_cadre, "Nom\n et Adresse\n du tiré", 0, R);
         $pdf->SetXY($curx + $largeur_cadre + 2, $cury - 0.5);
         $pdf->SetFont(pdf_getPDFFont($outputlangs), 'B', 8);
         $arrayidcontact = $object->getIdContact('external', 'BILLING');
         $carac_client = $outputlangs->convToOutputCharset($object->client->nom);
         $carac_client .= "\n" . $outputlangs->convToOutputCharset(!empty($object->client->address) ? $object->client->address : $object->client->adresse);
         $carac_client .= "\n" . $outputlangs->convToOutputCharset(!empty($object->client->zip) ? $object->client->zip : $object->client->cp) . " " . $outputlangs->convToOutputCharset(!empty($object->client->town) ? $object->client->town : $object->client->ville) . "\n";
         $pdf->MultiCell($largeur_cadre * 2.5, $hauteur_cadre, $carac_client, 1, C);
         //N� Siren
         $pdf->SetXY($curx, $cury + 16);
         $pdf->SetFont(pdf_getPDFFont($outputlangs), '', 6);
         $pdf->MultiCell($largeur_cadre, 4, "N° SIREN du tiré", 0, R);
         $pdf->SetXY($curx + $largeur_cadre + 2, $cury + 15.5);
         $pdf->SetFont(pdf_getPDFFont($outputlangs), 'B', 8);
         $pdf->MultiCell($largeur_cadre * 2.5, 4, $outputlangs->convToOutputCharset(empty($object->client->siren) ? $object->client->idprof1 : $object->client->siren), 1, C);
         //signature du tireur
         $pdf->SetXY($curx + $largeur_cadre * 5, $cury);
         $pdf->SetFont(pdf_getPDFFont($outputlangs), '', 6);
         $pdf->MultiCell($largeur_cadre * 2, 4, "Signature du tireur", 0, C);
         $pdf->Line(0, $cury + 40, $this->page_largeur, $cury + 40);
         $pdf->SetXY($curx + 100, $cury + 36);
         $pdf->SetFont(pdf_getPDFFont($outputlangs), '', 6);
         $pdf->MultiCell(50, 4, "Ne rien inscrire au dessous de cette ligne", 0, R);
         if (!empty($conf->global->LCR_GENERATE_ONE_PER_PAGE_WiTH_ADDRESS)) {
             // New page
             if ($ii < $nb_facture - 1) {
                 $pdf->AddPage();
             }
         } else {
             $posy += 96;
             $ii++;
             $res_modulo = $ii % 3;
             if ($res_modulo == 0) {
                 $pdf->AddPage();
                 $posy = 50;
             }
         }
     }
     //fin mb ///////////
 }
    function getFormMail($parameters, &$object, &$action, $hookmanager)
    {
        if (in_array('formmail', explode(':', $parameters['context']))) {
            if (!empty($object->param['facid'])) {
                global $db;
                $facture = new Facture($db);
                $facture->fetch((int) $object->param['facid']);
                //var_dump($facture);
                if ($facture->socid > 0) {
                    if (empty($facture->thirdparty)) {
                        $facture->fetch_thirdparty();
                    }
                    $societe =& $facture->thirdparty;
                    if (!empty($societe->array_options['options_facture_papier']) && $societe->array_options['options_facture_papier'] == 2) {
                        ?>
<script type="text/javascript">
						$(document).ready(function() {
							$("<div style=\"color:red;font-weight:bold;\">Attention ce client est paramétré par défaut en courrier</div>").dialog({
								modal:true
								,title:"Attention !"
								,buttons: {
						        	Ok: function() {
						          		$( this ).dialog( "close" );
						        	}
						      	}
							});
						});
						</script><?php 
                    }
                }
            }
        }
        return 0;
    }
function _parseNatixis(&$db, &$TRefFacture)
{
    global $conf, $langs;
    $TError = $TData = array();
    $currency = str_pad($conf->currency, 3);
    $cptLine = 2;
    //cpt à 2 pcq firstLine contient déjà le cpt à 1
    // Première ligne du fichier
    $firstLine = '01000001138FA053506' . $currency . date('Ymd');
    $firstLine .= str_repeat(' ', 22) . 'D';
    $firstLine .= str_repeat(' ', 77);
    $firstLine .= str_repeat('0', 30);
    $firstLine = array($firstLine);
    $total = 0;
    foreach ($TRefFacture as $ref) {
        $facture = new Facture($db);
        $facture->fetch('', $ref);
        $facture->fetch_thirdparty();
        $facnumber = str_replace('-', '', $facture->ref);
        if (empty($facture->thirdparty->code_compta)) {
            $TError['TErrorCodeCompta'][] = $langs->transnoentitiesnoconv('ErrorFactorEmptyCodeCompta', $facture->ref, $facture->thirdparty->name);
        }
        if (empty($facture->mode_reglement_code)) {
            $TError['TErrorModeReglt'][] = $langs->transnoentitiesnoconv('ErrorFactorEmptyModeReglt', $facture->ref);
        }
        if ($facture->type == 2) {
            $factype = 'AV';
            $date_ech = '        ';
            $mod = '   ';
        } else {
            $factype = 'FA';
            $date_ech = date('Ymd', $facture->date_lim_reglement);
            $mod = $facture->mode_reglement_code;
        }
        $TData[] = array('04', str_pad($cptLine, 6, 0, STR_PAD_LEFT), '138', $factype, '053506', $currency, '0', substr($facnumber, -7), str_pad($facture->thirdparty->code_compta, 10), str_repeat(' ', 5), date('Ymd', $facture->date), $date_ech, $mod, str_repeat(' ', 66), str_repeat('0', 15), str_pad(round($facture->total_ttc * 100), 15, 0, STR_PAD_LEFT));
        $total += round($facture->total_ttc * 100);
        $cptLine++;
    }
    $_SESSION['TErrorCodeCompta'] = $TError['TErrorCodeCompta'];
    $_SESSION['TErrorModeReglt'] = $TError['TErrorModeReglt'];
    $cptLine = str_pad($cptLine, 6, 0, STR_PAD_LEFT);
    // Dernière ligne du fichier
    $endLine = '09' . $cptLine . '138FA053506' . $currency . str_repeat(' ', 108);
    $endLine .= str_pad(count($TData), 15, 0, STR_PAD_LEFT);
    $endLine .= str_pad($total, 15, 0, STR_PAD_LEFT);
    $endLine = array($endLine);
    // write file
    $folder = $conf->entity == 1 ? DOL_DATA_ROOT . '/factor/' : DOL_DATA_ROOT . '/' . $conf->entity . '/factor/';
    dol_mkdir($folder);
    $fileName = 'export_natixis_' . date('Ymd') . '.txt';
    $fullPath = $folder . $fileName;
    $handle = fopen($fullPath, 'w');
    if ($handle) {
        fwrite($handle, implode('', $firstLine) . "\n");
        foreach ($TData as &$TInfo) {
            fwrite($handle, implode('', $TInfo) . "\n");
        }
        fwrite($handle, implode('', $endLine) . "\n");
        fclose($handle);
        return $fileName;
    } else {
        setEventMessages('ErrorCanNotCreateExportFile', array(), 'errors');
        return 0;
    }
}
예제 #9
0
    /**
     *      A record into bank for payment with links between this bank record and invoices of payment.
     *      All payment properties must have been set first like after a call to create().
     *      @param      user                Object of user making payment
     *      @param      mode                'payment', 'payment_supplier'
     *      @param      label               Label to use in bank record
     *      @param      accountid           Id of bank account to do link with
     *      @param      emetteur_nom        Name of transmitter
     *      @param      emetteur_banque     Name of bank
     *      @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;
        $this->fk_account=$accountid;

        if ($conf->banque->enabled)
        {
            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);
            $acc->fetch($this->fk_account);

            $totalamount=$this->amount;
            if (empty($totalamount)) $totalamount=$this->total; // For backward compatibility
            if ($mode == 'payment') $totalamount=$totalamount;
            if ($mode == 'payment_supplier') $totalamount=-$totalamount;

            // Insert payment into llx_bank
            $bank_line_id = $acc->addline($this->datepaye,
            $this->paiementid,  // Payment mode id or code ("CHQ or VIR for example")
            $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/fiche.php?id=';
                    if ($mode == 'payment_supplier') $url=DOL_URL_ROOT.'/fourn/paiement/fiche.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)
                {
                    $linkaddedforthirdparty=array();
                    foreach ($this->amounts as $key => $value)  // We should have always same third party but we loop in case of.
                    {
                        if ($mode == 'payment')
                        {
                            $fac = new Facture($this->db);
                            $fac->fetch($key);
                            $fac->fetch_thirdparty();
                            if (! in_array($fac->thirdparty->id,$linkaddedforthirdparty)) // Not yet done for this thirdparty
                            {
                                $result=$acc->add_url_line($bank_line_id, $fac->thirdparty->id,
                                DOL_URL_ROOT.'/comm/fiche.php?socid=', $fac->thirdparty->nom, 'company');
                                if ($result <= 0) dol_print_error($this->db);
                                $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)) // Not yet done for this thirdparty
                            {
                                $result=$acc->add_url_line($bank_line_id, $fac->thirdparty->id,
                                DOL_URL_ROOT.'/fourn/fiche.php?socid=', $fac->thirdparty->nom, 'company');
                                if ($result <= 0) dol_print_error($this->db);
                                $linkaddedforthirdparty[$fac->thirdparty->id]=$fac->thirdparty->id;  // Mark as done for this thirdparty
                            }
                        }
                    }
                }

	            if (! $error && ! $notrigger)
				{
					// Appel des triggers
					include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
					$interface=new Interfaces($this->db);
					$result=$interface->run_triggers('PAYMENT_ADD_TO_BANK',$this,$user,$langs,$conf);
					if ($result < 0) { $error++; $this->errors=$interface->errors; }
					// Fin appel triggers
				}
            }
            else
            {
                $this->error=$acc->error;
                $error++;
            }
        }

        if (! $error)
        {
            return $bank_line_id;
        }
        else
        {
            return -1;
        }
    }
예제 #10
0
/**
 *	Create a meta file with document file into same directory.
 *  This should allow rgrep search.
 *	@param	    db  		Objet base de donnee
 *	@param	    facid		Id de la facture a creer
 *	@param      message     Message
 */
function facture_meta_create($db, $facid, $message="")
{
	global $langs,$conf;

	$fac = new Facture($db,"",$facid);
	$fac->fetch($facid);
	$fac->fetch_thirdparty();

	if ($conf->facture->dir_output)
	{
		$facref = dol_sanitizeFileName($fac->ref);
		$dir = $conf->facture->dir_output . "/" . $facref ;
		$file = $dir . "/" . $facref . ".meta";

		if (! is_dir($dir))
		{
			create_exdir($dir);
		}

		if (is_dir($dir))
		{
			$nblignes = sizeof($fac->lines);
			$client = $fac->client->nom . " " . $fac->client->address . " " . $fac->client->cp . " " . $fac->client->ville;
			$meta = "REFERENCE=\"" . $fac->ref . "\"
			DATE=\"" . dol_print_date($fac->date,'') . "\"
			NB_ITEMS=\"" . $nblignes . "\"
			CLIENT=\"" . $client . "\"
			TOTAL_HT=\"" . $fac->total_ht . "\"
			TOTAL_TTC=\"" . $fac->total_ttc . "\"\n";

			for ($i = 0 ; $i < $nblignes ; $i++)
			{
				//Pour les articles
				$meta .= "ITEM_" . $i . "_QUANTITY=\"" . $fac->lines[$i]->qty . "\"
				ITEM_" . $i . "_UNIT_PRICE=\"" . $fac->lines[$i]->price . "\"
				ITEM_" . $i . "_TVA=\"" .$fac->lines[$i]->tva_tx . "\"
				ITEM_" . $i . "_DESCRIPTION=\"" . str_replace("\r\n","",nl2br($fac->lines[$i]->desc)) . "\"
				";
			}
		}
		$fp = fopen ($file,"w");
		fputs($fp,$meta);
		fclose($fp);
		if (! empty($conf->global->MAIN_UMASK))
		@chmod($file, octdec($conf->global->MAIN_UMASK));
	}
}