public function payerLoyerAction()
 {
     $paiement = new Paiement();
     $paiement->montant = $_GET['loyer'];
     $paiement->date = "2015-12-17";
     $paiement->mode = "enLigne";
     $paiement->type = "locataireVersAgence";
     $paiement->id_utilisateur = $_GET['id_utilisateur'];
     $paiement->id_location = $_GET['id_location'];
     $paiement->insert();
     // Redirection vers la page d'accueil
     header("Location: index.php?a=displayLoc");
 }
Exemple #2
0
 public static function getInstance()
 {
     if (self::$singleton === null) {
         self::$singleton = new Paiement();
     }
     return self::$singleton;
 }
function listerTout()
{
    // Liste de tous les paiements
    echo "Liste des paiements disponibles dans la base : <br/>";
    $listePaiements = Paiement::findAll();
    foreach ($listePaiements as $value) {
        $value->afficher();
    }
}
Exemple #4
0
    require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php';
}
$langs->load('bills');
$langs->load('banks');
$langs->load('companies');
// Security check
$id = GETPOST('id', 'int');
$action = GETPOST('action', 'alpha');
$confirm = GETPOST('confirm', 'alpha');
if ($user->societe_id) {
    $socid = $user->societe_id;
}
// TODO ajouter regle pour restreindre acces paiement
//$result = restrictedArea($user, 'facture', $id,'');
$mesg = '';
$object = new Paiement($db);
/*
 * Actions
 */
if ($action == 'setnote' && $user->rights->facture->paiement) {
    $db->begin();
    $object->fetch($id);
    $result = $object->update_note(GETPOST('note'));
    if ($result > 0) {
        $db->commit();
        $action = '';
    } else {
        $mesg = '<div class="error">' . $object->error . '</div>';
        $db->rollback();
    }
}
Exemple #5
0
 */
if ($action == 'add_paiement') {
    if ($error) {
        $action = 'create';
    }
    // Le reste propre a cette action s'affiche en bas de page.
}
/*
 * Action confirm_paiement
 */
if ($action == 'confirm_paiement' && $confirm == 'yes') {
    $error = 0;
    $datepaye = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
    $db->begin();
    // Creation of payment line
    $paiement = new Paiement($db);
    $paiement->datepaye = $datepaye;
    $paiement->amounts = $amounts;
    // Array with all payments dispatching
    $paiement->paiementid = dol_getIdFromCode($db, $_POST['paiementcode'], 'c_paiement');
    $paiement->num_paiement = $_POST['num_paiement'];
    $paiement->note = $_POST['comment'];
    if (!$error) {
        $paiement_id = $paiement->create($user, GETPOST('closepaidinvoices') == 'on' ? 1 : 0);
        if ($paiement_id < 0) {
            $errmsg = $paiement->error;
            $error++;
        }
    }
    if (!$error) {
        $result = $paiement->addPaymentToBank($user, 'payment', '(CustomerInvoicePayment)', $_POST['accountid'], $_POST['chqemetteur'], $_POST['chqbank']);
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;
        $valarray = explode('=', $value);
        $newlangid = $valarray[1];
        print 'Use language ' . $newlangid . ".\n";
    }
 // Clean parameters amount if payment is for a credit note
 if (GETPOST('type') == 2) {
     foreach ($amounts as $key => $value) {
         $newvalue = price2num($value, 'MT');
         $amounts[$key] = -$newvalue;
     }
 }
 if (!empty($conf->banque->enabled)) {
     // Si module bank actif, un compte est obligatoire lors de la saisie d'un paiement
     if (GETPOST('accountid') <= 0) {
         setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentities('AccountToCredit')), 'errors');
         $error++;
     }
 }
 // Creation of payment line
 $paiement = new Paiement($db);
 $paiement->datepaye = $datepaye;
 $paiement->amounts = $amounts;
 // Array with all payments dispatching
 $paiement->paiementid = dol_getIdFromCode($db, $_POST['paiementcode'], 'c_paiement');
 $paiement->num_paiement = $_POST['num_paiement'];
 $paiement->note = $_POST['comment'];
 if (!$error) {
     $paiement_id = $paiement->create($user, GETPOST('closepaidinvoices') == 'on' ? 1 : 0);
     if ($paiement_id < 0) {
         setEventMessage($paiement->error, 'errors');
         $error++;
     }
 }
 if (!$error) {
     $label = '(CustomerInvoicePayment)';
Exemple #8
0
 *   	\file       htdocs/compta/paiement/info.php
 *		\ingroup    facture
 *		\brief      Onglet info d'un paiement
 */
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
require_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/payments.lib.php';
$langs->load("bills");
$langs->load("companies");
$id = GETPOST('id');
/*
 * View
 */
llxHeader();
$paiement = new Paiement($db);
$paiement->fetch($id);
$paiement->info($id);
$head = payment_prepare_head($paiement);
dol_fiche_head($head, 'info', $langs->trans("PaymentCustomerInvoice"), 0, 'payment');
print '<table class="border" width="100%">';
// Ref
print '<tr><td valign="top" width="140">' . $langs->trans('Ref') . '</td><td colspan="3">' . $paiement->id . '</td></tr>';
print '</table>';
print '<br>';
print '<table width="100%"><tr><td>';
dol_print_object_info($paiement);
print '</td></tr></table>';
print '</div>';
$db->close();
llxFooter();
 /**
  *	Set withdrawal to credited status
  *
  *	@param	User		$user		id of user
  *	@param 	timestamp	$date		date of action
  *	@return	int						>0 if OK, <0 if KO
  */
 function set_infocredit($user, $date)
 {
     global $conf, $langs;
     $error = 0;
     if ($this->_fetched == 1) {
         if ($date >= $this->date_trans) {
             if ($this->db->begin()) {
                 $sql = " UPDATE " . MAIN_DB_PREFIX . "prelevement_bons ";
                 $sql .= " SET fk_user_credit = " . $user->id;
                 $sql .= ", statut = 2";
                 $sql .= ", date_credit = '" . $this->db->idate($date) . "'";
                 $sql .= " WHERE rowid=" . $this->id;
                 $sql .= " AND entity = " . $conf->entity;
                 $sql .= " AND statut = 1";
                 if ($this->db->query($sql)) {
                     $langs->load('withdrawals');
                     $subject = $langs->trans("InfoCreditSubject", $this->ref);
                     $message = $langs->trans("InfoCreditMessage", $this->ref, dol_print_date($date, 'dayhour'));
                     //Add payment of withdrawal into bank
                     $bankaccount = $conf->global->PRELEVEMENT_ID_BANKACCOUNT;
                     $facs = array();
                     $amounts = array();
                     $facs = $this->getListInvoices(1);
                     $num = count($facs);
                     for ($i = 0; $i < $num; $i++) {
                         $fac = new Facture($this->db);
                         $fac->fetch($facs[$i][0]);
                         $amounts[$fac->id] = $facs[$i][1];
                         $result = $fac->set_paid($user);
                     }
                     $paiement = new Paiement($this->db);
                     $paiement->datepaye = $date;
                     $paiement->amounts = $amounts;
                     $paiement->paiementid = 3;
                     //
                     $paiement->num_paiement = $this->ref;
                     $paiement_id = $paiement->create($user);
                     if ($paiement_id < 0) {
                         dol_syslog(get_class($this) . "::set_credite AddPayment Error");
                         $error++;
                     } else {
                         $result = $paiement->addPaymentToBank($user, 'payment', '(WithdrawalPayment)', $bankaccount, '', '');
                         if ($result < 0) {
                             dol_syslog(get_class($this) . "::set_credite AddPaymentToBank Error");
                             $error++;
                         }
                     }
                     // Update prelevement line
                     // TODO: Translate to ligneprelevement.class.php
                     $sql = " UPDATE " . MAIN_DB_PREFIX . "prelevement_lignes";
                     $sql .= " SET statut = 2";
                     $sql .= " WHERE fk_prelevement_bons = " . $this->id;
                     if (!$this->db->query($sql)) {
                         dol_syslog(get_class($this) . "::set_credite Update lines Error");
                         $error++;
                     }
                 } else {
                     dol_syslog(get_class($this) . "::set_infocredit Update Bons Error");
                     $error++;
                 }
                 /*
                  * End of procedure
                  */
                 if ($error == 0) {
                     $this->db->commit();
                     return 0;
                 } else {
                     $this->db->rollback();
                     dol_syslog("bon-prelevment::set_infocredit ROLLBACK ");
                     return -1;
                 }
             } else {
                 dol_syslog(get_class($this) . "::set_infocredit 1025 Open SQL transaction impossible ");
                 return -1025;
             }
         } else {
             dol_syslog("bon-prelevment::set_infocredit 1027 Date de credit < Date de trans ");
             return -1027;
         }
     } else {
         return -1026;
     }
 }
Exemple #10
0
         $sql = "SELECT p.rowid, p.datep as dp, pf.amount, p.statut,";
         $sql .= " p.fk_user_creat, u.login, u.rowid as userid";
         $sql .= " FROM " . MAIN_DB_PREFIX . "paiement_facture as pf,";
         $sql .= " " . MAIN_DB_PREFIX . "paiement as p";
         $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "user as u ON p.fk_user_creat = u.rowid";
         $sql .= " WHERE pf.fk_paiement = p.rowid";
         $sql .= " AND p.entity = " . $conf->entity;
         $sql .= " AND pf.fk_facture = " . $fac->id;
         $sql .= " ORDER BY p.datep ASC";
         $resqlp = $db->query($sql);
         if ($resqlp) {
             $nump = $db->num_rows($resqlp);
             $j = 0;
             while ($j < $nump) {
                 $objp = $db->fetch_object($resqlp);
                 $paymentstatic = new Paiement($db);
                 $paymentstatic->id = $objp->rowid;
                 $userstatic->id = $objp->userid;
                 $userstatic->login = $objp->login;
                 $TData[] = array('date' => $db->jdate($objp->dp), 'link' => $langs->trans("Payment") . ' ' . $paymentstatic->getNomUrl(1), 'status' => '', 'amount' => -$objp->amount, 'author' => $userstatic->getLoginUrl(1));
                 $TDataSort[] = $db->jdate($objp->dp);
                 $j++;
             }
             $db->free($resqlp);
         } else {
             dol_print_error($db);
         }
     }
 } else {
     dol_print_error($db);
 }
Exemple #11
0
            print '</tr>';
            $i++;
        }
        print "</table>";
        print '<div class="tabsAction">';
        if ($user->rights->banque->cheque) {
            print '<input type="submit" class="button" value="' . $langs->trans('NewCheckDepositOn', $account_label) . '">';
        } else {
            print '<a class="butActionRefused" href="#" title="' . $langs->trans("NotEnoughPermissions") . '">' . $langs->trans('NewCheckDepositOn', $account_label) . '</a>';
        }
        print '</div><br>';
        print '</form>';
    }
} else {
    $linkback = '<a href="' . $_SERVER["PHP_SELF"] . '?leftmenu=customers_bills_checks&action=new">' . $langs->trans("BackToList") . '</a>';
    $paymentstatic = new Paiement($db);
    $accountlinestatic = new AccountLine($db);
    $accountstatic = new Account($db);
    $accountstatic->id = $object->account_id;
    $accountstatic->label = $object->account_label;
    print '<table class="border" width="100%">';
    print '<tr><td width=20%>';
    print '<table class="nobordernopadding" width="100%"><tr><td>';
    print $langs->trans('Ref');
    print '</td>';
    if ($action != 'editref') {
        print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editref&amp;id=' . $object->id . '">' . img_edit($langs->trans('SetRef'), 1) . '</a></td>';
    }
    print '</tr></table>';
    print '</td><td colspan="2">';
    if ($action == 'editref') {
function _setPayment($user, $db, $conf, $langs)
{
    $TPayment = GETPOST('payment', 'array');
    $fk_bank = GETPOST('fk_bank', 'int');
    if (empty($fk_bank)) {
        if (function_exists('setEventMessages')) {
            setEventMessages($langs->transnoentitiesnoconv('ErrorPaymentImportNoBankSelected'), array(), 'errors');
        } else {
            setEventMessage($langs->transnoentitiesnoconv('ErrorPaymentImportNoBankSelected'), 'errors');
        }
        return;
    }
    $mode_reglement = GETPOST('paiementcode', 'alpha');
    $TFactureNotFound = $TPaimentError = $TWriteBankFail = array();
    $nb_facture_not_found = $nb_payment = $nb_writebank = 0;
    foreach ($TPayment as $TInfoPayment) {
        $facture_ref = trim($TInfoPayment['facture_ref']);
        $rib = trim($TInfoPayment['rib']);
        $amount = price2num($TInfoPayment['amount']);
        $date_creation = trim($TInfoPayment['date_creation']);
        $num_payment = trim($TInfoPayment['num_payment']);
        $note = trim($TInfoPayment['note']);
        if ($amount <= 0) {
            continue;
        }
        $facture = new Facture($db);
        if ($facture->fetch(null, $facture_ref) > 0) {
            if ($facture->paye) {
                $TFactureAlreadyPaid[] = $langs->transnoentitiesnoconv('paymentimport_warningFactureAlreadyPaid', $facture_ref);
                continue;
                // Sécurité si jamais la facture est déjà payé on ne saisie pas de nouveau règlement
            }
            if (!empty($conf->global->PAYMENTIMPORT_FORCE_DATE_TODAY)) {
                $datepaye = dol_mktime(date('H'), date('m'), date('s'), date('m'), date('d'), date('Y'));
            } else {
                $date_creation = explode('/', $date_creation);
                $datepaye = dol_mktime(12, 0, 0, $date_creation[1], $date_creation[0], $date_creation[2]);
            }
            if (empty($mode_reglement)) {
                $paiementcode = $facture->mode_reglement_code;
            } else {
                $paiementcode = $mode_reglement;
            }
            // Creation of payment line
            $paiement = new Paiement($db);
            $paiement->datepaye = $datepaye;
            $paiement->amounts = array($facture->id => $amount);
            // Array with all payments dispatching
            $paiement->paiementid = dol_getIdFromCode($db, $paiementcode, 'c_paiement');
            $paiement->num_paiement = $num_payment;
            $paiement->note = $note;
            $paiement_id = $paiement->create($user, 1);
            if ($paiement_id > 0) {
                $nb_payment++;
                $label = '(CustomerInvoicePayment)';
                $result = $paiement->addPaymentToBank($user, 'payment', $label, $fk_bank, '', '');
                if ($result > 0) {
                    $nb_writebank++;
                } else {
                    $TWriteBankFail[] = $langs->transnoentitiesnoconv('paymentimport_errorwritebank', $facture_ref);
                }
            } else {
                $TPaimentError[] = $langs->transnoentitiesnoconv('paymentimport_errorpayment', $facture_ref, $rib, $amount);
            }
        } else {
            $TFactureNotFound[] = $langs->transnoentitiesnoconv('paymentimport_errorfactnotfound', $facture_ref);
            $nb_facture_not_found++;
        }
    }
    if ($nb_facture_not_found > 0) {
        if (function_exists('setEventMessages')) {
            setEventMessages($langs->trans('paymentimport_nb_facture_not_found', $nb_facture_not_found), array(), 'errors');
        } else {
            setEventMessage($langs->trans('paymentimport_nb_facture_not_found', $nb_facture_not_found), 'errors');
        }
    }
    if ($nb_payment > 0) {
        if (function_exists('setEventMessages')) {
            setEventMessages($langs->trans('paymentimport_nb_payment', $nb_payment), array());
        } else {
            setEventMessage($langs->trans('paymentimport_nb_payment', $nb_payment));
        }
    }
    if ($nb_writebank > 0) {
        if (function_exists('setEventMessages')) {
            setEventMessages($langs->trans('paymentimport_nb_writebank', $nb_writebank), array());
        } else {
            setEventMessage($langs->trans('paymentimport_nb_writebank', $nb_writebank));
        }
    }
    $_SESSION['TFactureNotFound'] = $TFactureNotFound;
    $_SESSION['TPaimentError'] = $TPaimentError;
    $_SESSION['TWriteBankFail'] = $TWriteBankFail;
    $_SESSION['TFactureAlreadyPaid'] = $TFactureAlreadyPaid;
}
Exemple #13
0
	    $langs->load("errors");
		$mesg='<div class="error">'.$langs->trans($paiement->error).'</div>';
		$db->rollback();
	}
}


/*
 * View
 */

llxHeader();

$thirdpartystatic=new Societe($db);

$paiement = new Paiement($db);
$result=$paiement->fetch($id);
if ($result <= 0)
{
	dol_print_error($db,'Payement '.$id.' not found in database');
	exit;
}

$html = new Form($db);

$h=0;

$head[$h][0] = DOL_URL_ROOT.'/compta/paiement/fiche.php?id='.$id;
$head[$h][1] = $langs->trans("Card");
$hselected = $h;
$h++;
Exemple #14
0
function tripusr_paypal()
{
    global $root;
    require $root . 'libs' . DS . 'caddie_paie.php';
    $paiement = Paiement::getInstance();
    $paiement->addProduct('Voyage', 10);
    $paiement->sendRequest();
}
Exemple #15
0
     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">';
 //print "> ".$conf->global->PAYMENT_ADDON." - ".$file;
 if ($conf->global->PAYMENT_ADDON == $file || $conf->global->PAYMENT_ADDON . '.php' == $file) {
     print img_picto($langs->trans("Activated"), 'switch_on');
 } else {
     print '<a href="' . $_SERVER["PHP_SELF"] . '?action=setmod&value=' . preg_replace('/\\.php$/', '', $file) . '&scandir=' . $module->scandir . '&label=' . urlencode($module->name) . '" alt="' . $langs->trans("Default") . '">' . img_picto($langs->trans("Disabled"), 'switch_off') . '</a>';
 }
 print '</td>';
 $payment = new Paiement($db);
 $payment->initAsSpecimen();
 // Example
 $htmltooltip = '';
 $htmltooltip .= '' . $langs->trans("Version") . ': <b>' . $module->getVersion() . '</b><br>';
 $nextval = $module->getNextValue($mysoc, $payment);
 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>';
Exemple #16
0
$sql = "SELECT b.rowid , b.dateo as do, b.datev as dv, b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type, soc.code_compta, ba.courant,";
$sql .= " soc.code_compta_fournisseur, soc.rowid as socid, soc.nom as name, ba.account_number, bu1.type as typeop";
$sql .= " FROM " . MAIN_DB_PREFIX . "bank as b";
$sql .= " JOIN " . MAIN_DB_PREFIX . "bank_account as ba on b.fk_account=ba.rowid";
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "bank_url as bu1 ON bu1.fk_bank = b.rowid AND bu1.type='company'";
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as soc on bu1.url_id=soc.rowid";
$sql .= " WHERE ba.rowid=" . $id_bank_account;
if (!empty($conf->multicompany->enabled)) {
    $sql .= " AND ba.entity = " . $conf->entity;
}
if ($date_start && $date_end) {
    $sql .= " AND b.dateo >= '" . $db->idate($date_start) . "' AND b.dateo <= '" . $db->idate($date_end) . "'";
}
$sql .= " ORDER BY b.datev";
$object = new Account($db);
$paymentstatic = new Paiement($db);
$paymentsupplierstatic = new PaiementFourn($db);
$societestatic = new Societe($db);
$userstatic = new User($db);
$chargestatic = new ChargeSociales($db);
$paymentdonstatic = new PaymentDonation($db);
$paymentvatstatic = new TVA($db);
$paymentsalstatic = new PaymentSalary($db);
// Get code of finance journal
$bank_code_journal = new Account($db);
$result = $bank_code_journal->fetch($id_bank_account);
$journal = $bank_code_journal->accountancy_journal;
dol_syslog("accountancy/journal/bankjournal.php", LOG_DEBUG);
$result = $db->query($sql);
if ($result) {
    $num = $db->num_rows($result);
 /**
  *	Check return management
  *	Reopen linked invoices and create a new negative payment.
  *
  *	@param	int		$bank_id 		   Id of bank transaction line concerned
  *	@param	date	$rejection_date    Date to use on the negative payment
  * 	@return	int                        Id of negative payment line created 
  */
 function rejectCheck($bank_id, $rejection_date)
 {
     global $db, $user;
     $payment = new Paiement($db);
     $payment->fetch(0, 0, $bank_id);
     $bankline = new AccountLine($db);
     $bankline->fetch($bank_id);
     /* Conciliation is allowed because when check is returned, a new line is created onto bank transaction log.
     		if ($bankline->rappro)
     		{
                 $this->error='ActionRefusedLineAlreadyConciliated';
     		    return -1;
     		}*/
     $this->db->begin();
     // Not conciliated, we can delete it
     //$bankline->delete($user);    // We delete
     $bankaccount = $payment->fk_account;
     // Get invoices list to reopen them
     $sql = 'SELECT pf.fk_facture, pf.amount';
     $sql .= ' FROM ' . MAIN_DB_PREFIX . 'paiement_facture as pf';
     $sql .= ' WHERE pf.fk_paiement = ' . $payment->id;
     $resql = $db->query($sql);
     if ($resql) {
         $rejectedPayment = new Paiement($db);
         $rejectedPayment->amounts = array();
         $rejectedPayment->datepaye = $rejection_date;
         $rejectedPayment->paiementid = dol_getIdFromCode($this->db, 'CHQ', 'c_paiement');
         $rejectedPayment->num_paiement = $payment->numero;
         while ($obj = $db->fetch_object($resql)) {
             $invoice = new Facture($db);
             $invoice->fetch($obj->fk_facture);
             $invoice->set_unpaid($user);
             $rejectedPayment->amounts[$obj->fk_facture] = price2num($obj->amount) * -1;
         }
         $result = $rejectedPayment->create($user);
         if ($result > 0) {
             // We created a negative payment, we also add the line as bank transaction
             $result = $rejectedPayment->addPaymentToBank($user, 'payment', '(CheckRejected)', $bankaccount, '', '');
             if ($result > 0) {
                 $result = $payment->reject();
                 if ($result > 0) {
                     $this->db->commit();
                     return $rejectedPayment->id;
                 } else {
                     $this->db->rollback();
                     return -1;
                 }
             } else {
                 $this->error = $rejectedPayment->error;
                 $this->errors = $rejectedPayment->errors;
                 $this->db->rollback();
                 return -1;
             }
         } else {
             $this->error = $rejectedPayment->error;
             $this->errors = $rejectedPayment->errors;
             $this->db->rollback();
             return -1;
         }
     } else {
         $this->error = $this->db->lasterror();
         $this->db->rollback();
         return -1;
     }
 }
 /**
  *
  * 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;
 }
    $facture = new Facturesim($db);
}
if ($pay == "cash") {
    $object->mode_reglement_id = $rowterminal[2];
} else {
    $object->mode_reglement_id = $rowterminal[4];
}
$facture->createFromOrder($object);
$user->getrights();
if ($conf->stock->enabled) {
    $result = $facture->validate($user, '', $rowterminal[5]);
} else {
    $result = $facture->validate($user, '', '');
}
$object->delete($user);
$payment = new Paiement($db);
$payment->datepaye = $now;
if ($pay == "cash") {
    $fk_bank = $rowterminal[1];
} else {
    $fk_bank = $rowterminal[3];
}
$payment->bank_account = $fk_bank;
$payment->amounts[$facture->id] = $object->total_ttc;
if ($pay == "cash") {
    $payment->paiementid = 4;
} else {
    $payment->paiementid = 6;
}
$payment->num_paiement = '';
$payment_id = $payment->create($user, 1);
 if (!$error) {
     // Validate invoice
     $result = $invoice->validate($user);
     if ($result <= 0) {
         $errmsg = $invoice->error;
         $errmsgs = $invoice->errors;
         $error++;
     }
 }
 // Add payment onto invoice
 if ($option == 'bankviainvoice' && $accountid) {
     require_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php';
     require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php';
     require_once DOL_DOCUMENT_ROOT . '/core/lib/functions.lib.php';
     $amounts[$invoice->id] = price2num($cotisation);
     $paiement = new Paiement($db);
     $paiement->datepaye = $paymentdate;
     $paiement->amounts = $amounts;
     $paiement->paiementid = dol_getIdFromCode($db, $operation, 'c_paiement');
     $paiement->num_paiement = $num_chq;
     $paiement->note = $label;
     if (!$error) {
         // Create payment line for invoice
         $paiement_id = $paiement->create($user);
         if (!$paiement_id > 0) {
             $errmsg = $paiement->error;
             $errmsgs = $paiement->errors;
             $error++;
         }
     }
     if (!$error) {
/**
 *   	\file       htdocs/compta/paiement/info.php
 *		\ingroup    facture
 *		\brief      Onglet info d'un paiement
 */
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
require_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/payments.lib.php';
$langs->load("bills");
$langs->load("companies");
/*
 * View
 */
llxHeader();
$paiement = new Paiement($db);
$paiement->fetch($_GET["id"], $user);
$paiement->info($_GET["id"]);
$head = payment_prepare_head($paiement);
dol_fiche_head($head, 'info', $langs->trans("PaymentCustomerInvoice"), 0, 'payment');
print '<table class="border" width="100%">';
// Ref
print '<tr><td valign="top" width="140">' . $langs->trans('Ref') . '</td><td colspan="3">' . $paiement->id . '</td></tr>';
print '</table>';
print '<br>';
print '<table width="100%"><tr><td>';
dol_print_object_info($paiement);
print '</td></tr></table>';
print '</div>';
$db->close();
llxFooter();
 // Si paiement differe ...
 if ($obj_facturation->getSetPaymentMode() == 'DIF') {
     $resultcreate = $invoice->create($user, 0, dol_stringtotime($obj_facturation->paiementLe()));
     if ($resultcreate > 0) {
         $resultvalid = $invoice->validate($user, $obj_facturation->numInvoice());
     } else {
         $error++;
     }
     $id = $invoice->id;
 } else {
     $resultcreate = $invoice->create($user, 0, 0);
     if ($resultcreate > 0) {
         $resultvalid = $invoice->validate($user, $obj_facturation->numInvoice(), isset($_SESSION["CASHDESK_ID_WAREHOUSE"]) ? $_SESSION["CASHDESK_ID_WAREHOUSE"] : 0);
         $id = $invoice->id;
         // Add the payment
         $payment = new Paiement($db);
         $payment->datepaye = $now;
         $payment->bank_account = $conf_fkaccount;
         $payment->amounts[$invoice->id] = $obj_facturation->prixTotalTtc();
         $payment->note = $langs->trans("Payment") . ' ' . $langs->trans("Invoice") . ' ' . $obj_facturation->numInvoice();
         $payment->paiementid = $invoice->mode_reglement_id;
         $payment->num_paiement = '';
         $paiement_id = $payment->create($user);
         if ($paiement_id > 0) {
             if (!$error) {
                 $result = $payment->addPaymentToBank($user, 'payment', '(CustomerInvoicePayment)', $bankaccountid, '', '');
                 if (!$result > 0) {
                     $errmsg = $paiement->error;
                     $error++;
                 }
             }
Exemple #23
0
 */
/**
 *   	\file       htdocs/compta/paiement/info.php
 *		\ingroup    facture
 *		\brief      Onglet info d'un paiement
 */
require "../../main.inc.php";
require_once DOL_DOCUMENT_ROOT . "/core/lib/functions2.lib.php";
require_once DOL_DOCUMENT_ROOT . "/compta/paiement/class/paiement.class.php";
$langs->load("bills");
$langs->load("companies");
/*
 * View
 */
llxHeader();
$paiement = new Paiement($db);
$paiement->fetch($_GET["id"], $user);
$paiement->info($_GET["id"]);
$h = 0;
$head[$h][0] = DOL_URL_ROOT . '/compta/paiement/fiche.php?id=' . $_GET["id"];
$head[$h][1] = $langs->trans("Card");
$h++;
$head[$h][0] = DOL_URL_ROOT . '/compta/paiement/info.php?id=' . $_GET["id"];
$head[$h][1] = $langs->trans("Info");
$hselected = $h;
$h++;
dol_fiche_head($head, $hselected, $langs->trans("PaymentCustomerInvoice"), 0, 'payment');
print '<table class="border" width="100%">';
// Ref
print '<tr><td valign="top" width="140">' . $langs->trans('Ref') . '</td><td colspan="3">' . $paiement->id . '</td></tr>';
print '</table>';
Exemple #24
0
if (!empty($conf->banque->enabled)) {
    require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php';
}
$langs->load('bills');
$langs->load('banks');
$langs->load('companies');
// Security check
$id = GETPOST('id', 'int');
$action = GETPOST('action', 'alpha');
$confirm = GETPOST('confirm', 'alpha');
if ($user->societe_id) {
    $socid = $user->societe_id;
}
// TODO ajouter regle pour restreindre acces paiement
//$result = restrictedArea($user, 'facture', $id,'');
$object = new Paiement($db);
/*
 * Actions
 */
if ($action == 'setnote' && $user->rights->facture->paiement) {
    $db->begin();
    $object->fetch($id);
    $result = $object->update_note(GETPOST('note'));
    if ($result > 0) {
        $db->commit();
        $action = '';
    } else {
        setEventMessage($object->error, 'errors');
        $db->rollback();
    }
}
    $object->fetch($id);
    $object->set_unpaid('admin');
    $sql = 'SELECT p.datep as dp, p.num_paiement, p.rowid, p.fk_bank,';
    $sql .= ' c.code as payment_code, c.libelle as payment_label,';
    $sql .= ' pf.amount,';
    $sql .= ' ba.rowid as baid, ba.ref, ba.label';
    $sql .= ' FROM ' . MAIN_DB_PREFIX . 'c_paiement as c, ' . MAIN_DB_PREFIX . 'paiement_facture as pf, ' . MAIN_DB_PREFIX . 'paiement as p';
    $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank as b ON p.fk_bank = b.rowid';
    $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'bank_account as ba ON b.fk_account = ba.rowid';
    $sql .= ' WHERE pf.fk_facture = ' . $id . ' AND p.fk_paiement = c.id AND pf.fk_paiement = p.rowid';
    $sql .= ' ORDER BY p.datep, p.tms';
    $result = $db->query($sql);
    if ($result) {
        $num = $db->num_rows($result);
        $objp = $db->fetch_object($result);
        $paiement = new Paiement($db);
        $paiement->fetch($objp->rowid);
        $paiement->delete();
    }
    if ($conf->stock->enabled) {
        $object->delete(0, 0, $conf->global->POS_DEFAULT_WAREHOUSE);
    } else {
        $object->delete();
    }
    $sql = 'delete from ' . MAIN_DB_PREFIX . 'pos_facture where fk_facture=' . $id;
    $db->query($sql);
}
//Get records from database
$sql = "SELECT rowid as iddet, facnumber, datec, fk_user_author as user, total_ttc as price FROM " . MAIN_DB_PREFIX . "facture order by rowid DESC limit 50";
$resql = $db->query($sql);
//Add all records to an array
Exemple #26
0
}
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->banque->modifier) {
    $accline = new AccountLine($db);
    $result = $accline->fetch(GETPOST("rowid"));
    $result = $accline->delete();
}
/*
 * View
 */
llxHeader('', $langs->trans("FinancialAccount") . '-' . $langs->trans("Transactions"));
$societestatic = new Societe($db);
$userstatic = new User($db);
$chargestatic = new ChargeSociales($db);
$loanstatic = new Loan($db);
$memberstatic = new Adherent($db);
$paymentstatic = new Paiement($db);
$paymentsupplierstatic = new PaiementFourn($db);
$paymentvatstatic = new TVA($db);
$paymentsalstatic = new PaymentSalary($db);
$donstatic = new Don($db);
$expensereportstatic = new ExpenseReport($db);
$bankstatic = new Account($db);
$banklinestatic = new AccountLine($db);
$form = new Form($db);
if ($id > 0 || !empty($ref)) {
    if ($vline) {
        $viewline = $vline;
    } else {
        $viewline = empty($conf->global->MAIN_SIZE_LISTE_LIMIT) ? 20 : $conf->global->MAIN_SIZE_LISTE_LIMIT;
    }
    $result = $object->fetch($id, $ref);
 /**
  * Create
  *
  * @param 	User		$user				User object
  * @param 	int			$id					Id
  * @param 	string		$motif				Motif
  * @param 	int	$date_rejet			Date rejet
  * @param 	int			$bonid				Bon id
  * @param 	int			$facturation		Facturation
  * @return	void
  */
 function create($user, $id, $motif, $date_rejet, $bonid, $facturation = 0)
 {
     global $langs, $conf;
     $error = 0;
     $this->id = $id;
     $this->bon_id = $bonid;
     $now = dol_now();
     dol_syslog("RejetPrelevement::Create id {$id}");
     $bankaccount = $conf->global->PRELEVEMENT_ID_BANKACCOUNT;
     $facs = $this->getListInvoices(1);
     $this->db->begin();
     // Insert refused line into database
     $sql = "INSERT INTO " . MAIN_DB_PREFIX . "prelevement_rejet (";
     $sql .= "fk_prelevement_lignes";
     $sql .= ", date_rejet";
     $sql .= ", motif";
     $sql .= ", fk_user_creation";
     $sql .= ", date_creation";
     $sql .= ", afacturer";
     $sql .= ") VALUES (";
     $sql .= $id;
     $sql .= ", '" . $this->db->idate($date_rejet) . "'";
     $sql .= ", " . $motif;
     $sql .= ", " . $user->id;
     $sql .= ", '" . $this->db->idate($now) . "'";
     $sql .= ", " . $facturation;
     $sql .= ")";
     $result = $this->db->query($sql);
     if (!$result) {
         dol_syslog("RejetPrelevement::create Erreur 4");
         dol_syslog("RejetPrelevement::create Erreur 4 {$sql}");
         $error++;
     }
     // Tag the line to refused
     $sql = " UPDATE " . MAIN_DB_PREFIX . "prelevement_lignes ";
     $sql .= " SET statut = 3";
     $sql .= " WHERE rowid = " . $id;
     if (!$this->db->query($sql)) {
         dol_syslog("RejetPrelevement::create Erreur 5");
         $error++;
     }
     $num = count($facs);
     for ($i = 0; $i < $num; $i++) {
         $fac = new Facture($this->db);
         $fac->fetch($facs[$i][0]);
         // Make a negative payment
         $pai = new Paiement($this->db);
         $pai->amounts = array();
         /*
          * We replace the comma with a point otherwise some
          * PHP installs sends only the part integer negative
          */
         $pai->amounts[$facs[$i][0]] = price2num($facs[$i][1] * -1);
         $pai->datepaye = $date_rejet;
         $pai->paiementid = 3;
         // type of payment: withdrawal
         $pai->num_paiement = $fac->ref;
         if ($pai->create($this->user) < 0) {
             $error++;
             dol_syslog("RejetPrelevement::Create Error creation payment invoice " . $facs[$i][0]);
         } else {
             $result = $pai->addPaymentToBank($user, 'payment', '(InvoiceRefused)', $bankaccount, '', '');
             if ($result < 0) {
                 dol_syslog("RejetPrelevement::Create AddPaymentToBan Error");
                 $error++;
             }
             // Payment validation
             if ($pai->valide() < 0) {
                 $error++;
                 dol_syslog("RejetPrelevement::Create Error payment validation");
             }
         }
         //Tag invoice as unpaid
         dol_syslog("RejetPrelevement::Create set_unpaid fac " . $fac->ref);
         $fac->set_unpaid($user);
         //TODO: Must be managed by notifications module
         // Send email to sender of the standing order request
         $this->_send_email($fac);
     }
     if ($error == 0) {
         dol_syslog("RejetPrelevement::Create Commit");
         $this->db->commit();
     } else {
         dol_syslog("RejetPrelevement::Create Rollback");
         $this->db->rollback();
     }
 }
Exemple #28
0
 * 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);
    $prevyear = $year_start;
    $prevquarter = $q;
Exemple #29
0
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
$langs->load("bills");
$langs->load("compta");
// Security check
$facid = GETPOST('facid', 'int');
$socid = GETPOST('socid', 'int');
$userid = GETPOST('userid', 'int');
$day = GETPOST('day', 'int');
$month = GETPOST('month', 'int');
$year = GETPOST('year', 'int');
if ($user->societe_id) {
    $socid = $user->societe_id;
}
$result = restrictedArea($user, 'facture', $facid, '');
$paymentstatic = new Paiement($db);
$accountstatic = new Account($db);
$companystatic = new Societe($db);
$search_ref = GETPOST("search_ref", "int");
$search_account = GETPOST("search_account", "int");
$search_paymenttype = GETPOST("search_paymenttype");
$search_amount = GETPOST("search_amount", 'alpha');
// alpha because we must be able to search on "< x"
$search_company = GETPOST("search_company", 'alpha');
$search_payment_num = GETPOST('search_payment_num', 'alpha');
$sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha');
$limit = GETPOST('limit') ? GETPOST('limit', 'int') : $conf->liste_limit;
$page = GETPOST("page", 'int');
if ($page == -1) {
    $page = 0;