Beispiel #1
0
    $cat1 = $_POST["cat1"];
    if (!$dateop) {
        $error++;
        setEventMessages($langs->trans("ErrorFieldRequired", $langs->trans("Date")), null, 'errors');
    }
    if (!$operation) {
        $error++;
        setEventMessages($langs->trans("ErrorFieldRequired", $langs->trans("Type")), null, 'errors');
    }
    if (!$amount) {
        $error++;
        setEventMessages($langs->trans("ErrorFieldRequired", $langs->trans("Amount")), null, 'errors');
    }
    if (!$error) {
        $object->fetch($id);
        $insertid = $object->addline($dateop, $operation, $label, $amount, $num_chq, $cat1, $user);
        if ($insertid > 0) {
            setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
            header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $id . "&action=addline");
            exit;
        } else {
            setEventMessages($object->error, $object->errors, 'errors');
        }
    } else {
        $action = 'addline';
    }
}
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->banque->modifier) {
    $accline = new AccountLine($db);
    $result = $accline->fetch(GETPOST("rowid"));
    $result = $accline->delete();
 // By default, electronic transfert from bank to bank
 $typefrom = 'PRE';
 $typeto = 'VIR';
 if ($accountto->courant == 2 || $accountfrom->courant == 2) {
     // This is transfert of change
     $typefrom = 'LIQ';
     $typeto = 'LIQ';
 }
 if (!$error) {
     $bank_line_id_from = $accountfrom->addline($dateo, $typefrom, $label, -1 * price2num($amount), '', '', $user);
 }
 if (!($bank_line_id_from > 0)) {
     $error++;
 }
 if (!$error) {
     $bank_line_id_to = $accountto->addline($dateo, $typeto, $label, price2num($amount), '', '', $user);
 }
 if (!($bank_line_id_to > 0)) {
     $error++;
 }
 if (!$error) {
     $result = $accountfrom->add_url_line($bank_line_id_from, $bank_line_id_to, DOL_URL_ROOT . '/compta/bank/ligne.php?rowid=', '(banktransfert)', 'banktransfert');
 }
 if (!($result > 0)) {
     $error++;
 }
 if (!$error) {
     $result = $accountto->add_url_line($bank_line_id_to, $bank_line_id_from, DOL_URL_ROOT . '/compta/bank/ligne.php?rowid=', '(banktransfert)', 'banktransfert');
 }
 if (!($result > 0)) {
     $error++;
 /**
  *      Add 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	$user               Object of user making payment
  *      @param  string	$mode               'payment_loan'
  *      @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
  *      @return int                 		<0 if KO, >0 if OK
  */
 function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
 {
     global $conf;
     $error = 0;
     if (!empty($conf->banque->enabled)) {
         require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php';
         $acc = new Account($this->db);
         $acc->fetch($accountid);
         $total = $this->total;
         if ($mode == 'payment_loan') {
             $total = -$total;
         }
         // Insert payment into llx_bank
         $bank_line_id = $acc->addline($this->datepaid, $this->paymenttype, $label, $total, $this->num_payment, '', $user, $emetteur_nom, $emetteur_banque);
         // Update fk_bank into llx_paiement.
         // We know the payment who generated the account write
         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_loan' in bank_url between payment and bank transaction
             $url = '';
             if ($mode == 'payment_loan') {
                 $url = DOL_URL_ROOT . '/loan/payment/card.php?id=';
             }
             if ($url) {
                 $result = $acc->add_url_line($bank_line_id, $this->id, $url, '(payment)', $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)
             //$linkaddedforthirdparty=array();
             if ($mode == 'payment_loan') {
                 $result = $acc->add_url_line($bank_line_id, $this->id, DOL_URL_ROOT . '/loan/card.php?id=', $this->label ? $this->label : '', 'loan');
                 if ($result <= 0) {
                     dol_print_error($this->db);
                 }
             }
         } else {
             $this->error = $acc->error;
             $error++;
         }
     }
     if (!$error) {
         return 1;
     } else {
         return -1;
     }
 }
Beispiel #4
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;
     }
 }
 /**
  *      Add 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	$user               Object of user making payment
  *      @param  string	$mode               'payment_donation'
  *      @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
  *      @return int                 		<0 if KO, >0 if OK
  */
 function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
 {
     global $conf;
     $error = 0;
     if (!empty($conf->banque->enabled)) {
         require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php';
         $acc = new Account($this->db);
         $acc->fetch($accountid);
         $total = $this->total;
         if ($mode == 'payment_donation') {
             $amount = $total;
         }
         // Insert payment into llx_bank
         $bank_line_id = $acc->addline($this->datepaid, $this->paymenttype, $label, $amount, $this->num_payment, '', $user, $emetteur_nom, $emetteur_banque);
         // Update fk_bank in 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', 'payment_donation' in bank_url between payment and bank transaction
             $url = '';
             if ($mode == 'payment_donation') {
                 $url = DOL_URL_ROOT . '/don/payment/card.php?rowid=';
             }
             if ($url) {
                 $result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode);
                 if ($result <= 0) {
                     $error++;
                     dol_print_error($this->db);
                 }
             }
         } else {
             $this->error = $acc->error;
             $error++;
         }
     }
     if (!$error) {
         return 1;
     } else {
         return -1;
     }
 }
 $db->begin();
 // Create subscription
 $crowid = $object->cotisation($datecotisation, $cotisation, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend);
 if ($crowid <= 0) {
     $error++;
     $errmsg = $object->error;
     setEventMessages($object->error, $object->errors, 'errors');
 }
 if (!$error) {
     // Insert into bank account directlty (if option choosed for) + link to llx_cotisation if option is 'bankdirect'
     if ($option == 'bankdirect' && $accountid) {
         require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php';
         $acct = new Account($db);
         $result = $acct->fetch($accountid);
         $dateop = $paymentdate;
         $insertid = $acct->addline($dateop, $operation, $label, $cotisation, $num_chq, '', $user, $emetteur_nom, $emetteur_banque);
         if ($insertid > 0) {
             $inserturlid = $acct->add_url_line($insertid, $object->id, DOL_URL_ROOT . '/adherents/card.php?rowid=', $object->getFullname($langs), 'member');
             if ($inserturlid > 0) {
                 // Met a jour la table cotisation
                 $sql = "UPDATE " . MAIN_DB_PREFIX . "cotisation SET fk_bank=" . $insertid;
                 $sql .= " WHERE rowid=" . $crowid;
                 dol_syslog("card_subscriptions::cotisation", LOG_DEBUG);
                 $resql = $db->query($sql);
                 if (!$resql) {
                     $error++;
                     $errmsg = $db->lasterror();
                 }
             } else {
                 $error++;
                 $errmsg = $acct->error;
    /**
     *      Add 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_sc'
     *      @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, >0 if OK
     */
    function addPaymentToBank($user,$mode,$label,$accountid,$emetteur_nom,$emetteur_banque)
    {
        global $conf;

        $error=0;

        if ($conf->banque->enabled)
        {
            require_once(DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php');

            $acc = new Account($this->db);
            $acc->fetch($accountid);

            $total=$this->total;
            if ($mode == 'payment_sc') $total=-$total;

            // Insert payment into llx_bank
            $bank_line_id = $acc->addline($this->datepaye,
            $this->paiementtype,  // Payment mode id or code ("CHQ or VIR for example")
            $label,
            $total,
            $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', 'payment_sc' in bank_url between payment and bank transaction
                $url='';
                if ($mode == 'payment_sc') $url=DOL_URL_ROOT.'/compta/payment_sc/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)
                $linkaddedforthirdparty=array();
                foreach ($this->amounts as $key => $value)
                {
                    if ($mode == 'payment_sc')
                    {
                        $socialcontrib = new ChargeSociales($this->db);
                        $socialcontrib->fetch($key);
                        $result=$acc->add_url_line($bank_line_id, $socialcontrib->id,
                        DOL_URL_ROOT.'/compta/charges.php?id=', $socialcontrib->type_libelle.(($socialcontrib->lib && $socialcontrib->lib!=$socialcontrib->type_libelle)?' ('.$socialcontrib->lib.')':''),'sc');
                        if ($result <= 0) dol_print_error($this->db);
                    }
                }
            }
            else
            {
                $this->error=$acc->error;
                $error++;
            }
        }

        if (! $error)
        {
            return 1;
        }
        else
        {
            return -1;
        }
    }
 /**
  *	Add a payment of localtax
  *
  *	@param		User	$user		Object user that insert
  *	@return		int					<0 if KO, rowid in localtax table if OK
  */
 function addPayment($user)
 {
     global $conf, $langs;
     $this->db->begin();
     // Check parameters
     $this->amount = price2num($this->amount);
     if (!$this->label) {
         $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label"));
         return -3;
     }
     if ($this->amount <= 0) {
         $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount"));
         return -4;
     }
     if (!empty($conf->banque->enabled) && (empty($this->accountid) || $this->accountid <= 0)) {
         $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Account"));
         return -5;
     }
     if (!empty($conf->banque->enabled) && (empty($this->paymenttype) || $this->paymenttype <= 0)) {
         $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode"));
         return -5;
     }
     // Insertion dans table des paiement localtax
     $sql = "INSERT INTO " . MAIN_DB_PREFIX . "localtax (localtaxtype, datep, datev, amount";
     if ($this->note) {
         $sql .= ", note";
     }
     if ($this->label) {
         $sql .= ", label";
     }
     $sql .= ", fk_user_creat, fk_bank";
     $sql .= ") ";
     $sql .= " VALUES (" . $this->ltt . ", '" . $this->db->idate($this->datep) . "',";
     $sql .= "'" . $this->db->idate($this->datev) . "'," . $this->amount;
     if ($this->note) {
         $sql .= ", '" . $this->db->escape($this->note) . "'";
     }
     if ($this->label) {
         $sql .= ", '" . $this->db->escape($this->label) . "'";
     }
     $sql .= ", '" . $user->id . "', NULL";
     $sql .= ")";
     dol_syslog(get_class($this) . "::addPayment", LOG_DEBUG);
     $result = $this->db->query($sql);
     if ($result) {
         $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "localtax");
         // TODO devrait s'appeler paiementlocaltax
         if ($this->id > 0) {
             $ok = 1;
             if (!empty($conf->banque->enabled)) {
                 // Insertion dans llx_bank
                 require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php';
                 $acc = new Account($this->db);
                 $result = $acc->fetch($this->accountid);
                 if ($result <= 0) {
                     dol_print_error($this->db);
                 }
                 $bank_line_id = $acc->addline($this->datep, $this->paymenttype, $this->label, -abs($this->amount), '', '', $user);
                 // Mise a jour fk_bank dans llx_localtax. On connait ainsi la ligne de localtax qui a g�n�r� l'�criture bancaire
                 if ($bank_line_id > 0) {
                     $this->update_fk_bank($bank_line_id);
                 } else {
                     $this->error = $acc->error;
                     $ok = 0;
                 }
                 // Mise a jour liens
                 $result = $acc->add_url_line($bank_line_id, $this->id, DOL_URL_ROOT . '/compta/localtax/card.php?id=', "(VATPayment)", "payment_vat");
                 if ($result < 0) {
                     $this->error = $acc->error;
                     $ok = 0;
                 }
             }
             if ($ok) {
                 $this->db->commit();
                 return $this->id;
             } else {
                 $this->db->rollback();
                 return -3;
             }
         } else {
             $this->error = $this->db->lasterror();
             $this->db->rollback();
             return -2;
         }
     } else {
         $this->error = $this->db->lasterror();
         $this->db->rollback();
         return -1;
     }
 }
 /**
  *  Create in database
  *
  *  @param      User	$user       User that create
  *  @return     int      			<0 if KO, >0 if OK
  */
 function create($user)
 {
     global $conf, $langs;
     $error = 0;
     // Clean parameters
     $this->amount = price2num(trim($this->amount));
     $this->label = trim($this->label);
     $this->note = trim($this->note);
     $this->fk_bank = trim($this->fk_bank);
     $this->fk_user_creat = trim($this->fk_user_creat);
     $this->fk_user_modif = trim($this->fk_user_modif);
     // Check parameters
     if (!$this->label) {
         $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label"));
         return -3;
     }
     if ($this->fk_user < 0 || $this->fk_user == '') {
         $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Employee"));
         return -4;
     }
     if ($this->amount < 0 || $this->amount == '') {
         $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount"));
         return -5;
     }
     if (!empty($conf->banque->enabled) && (empty($this->accountid) || $this->accountid <= 0)) {
         $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Account"));
         return -6;
     }
     if (!empty($conf->banque->enabled) && (empty($this->type_payment) || $this->type_payment <= 0)) {
         $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode"));
         return -7;
     }
     $this->db->begin();
     // Insert into llx_payment_salary
     $sql = "INSERT INTO " . MAIN_DB_PREFIX . "payment_salary (fk_user";
     $sql .= ", datep";
     $sql .= ", datev";
     $sql .= ", amount";
     $sql .= ", fk_typepayment";
     $sql .= ", num_payment";
     if ($this->note) {
         $sql .= ", note";
     }
     $sql .= ", label";
     $sql .= ", datesp";
     $sql .= ", dateep";
     $sql .= ", fk_user_creat";
     $sql .= ", fk_bank";
     $sql .= ", entity";
     $sql .= ") ";
     $sql .= " VALUES (";
     $sql .= "'" . $this->fk_user . "'";
     $sql .= ", '" . $this->db->idate($this->datep) . "'";
     $sql .= ", '" . $this->db->idate($this->datev) . "'";
     $sql .= ", '" . $this->amount . "'";
     $sql .= ", '" . $this->type_payment . "'";
     $sql .= ", '" . $this->num_payment . "'";
     if ($this->note) {
         $sql .= ", '" . $this->db->escape($this->note) . "'";
     }
     $sql .= ", '" . $this->db->escape($this->label) . "'";
     $sql .= ", '" . $this->db->idate($this->datesp) . "'";
     $sql .= ", '" . $this->db->idate($this->dateep) . "'";
     $sql .= ", '" . $user->id . "'";
     $sql .= ", NULL";
     $sql .= ", " . $conf->entity;
     $sql .= ")";
     dol_syslog(get_class($this) . "::create", LOG_DEBUG);
     $result = $this->db->query($sql);
     if ($result) {
         $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "payment_salary");
         if ($this->id > 0) {
             if (!empty($conf->banque->enabled) && !empty($this->amount)) {
                 // Insert into llx_bank
                 require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php';
                 $acc = new Account($this->db);
                 $result = $acc->fetch($this->accountid);
                 if ($result <= 0) {
                     dol_print_error($this->db);
                 }
                 // Insert payment into llx_bank
                 // Add link 'payment_salary' in bank_url between payment and bank transaction
                 $bank_line_id = $acc->addline($this->datep, $this->type_payment, $this->label, -abs($this->amount), $this->num_payment, '', $user);
                 // Update fk_bank into llx_paiement.
                 // So we know the payment which has generate the banking ecriture
                 if ($bank_line_id > 0) {
                     $this->update_fk_bank($bank_line_id);
                 } else {
                     $this->error = $acc->error;
                     $error++;
                 }
                 if (!$error) {
                     // Add link 'payment_salary' in bank_url between payment and bank transaction
                     $url = DOL_URL_ROOT . '/compta/salaries/card.php?id=';
                     $result = $acc->add_url_line($bank_line_id, $this->id, $url, "(SalaryPayment)", "payment_salary");
                     if ($result <= 0) {
                         $this->error = $acc->error;
                         $error++;
                     }
                 }
                 $fuser = new User($this->db);
                 $fuser->fetch($this->fk_user);
                 // Add link 'user' in bank_url between operation and bank transaction
                 $result = $acc->add_url_line($bank_line_id, $this->fk_user, DOL_URL_ROOT . '/user/card.php?id=', $langs->trans("SalaryPayment") . ' ' . $fuser->getFullName($langs) . ' ' . dol_print_date($this->datesp, 'dayrfc') . ' ' . dol_print_date($this->dateep, 'dayrfc'), 'user');
                 if ($result <= 0) {
                     $this->error = $acc->error;
                     $error++;
                 }
             }
             // Call trigger
             $result = $this->call_trigger('PAYMENT_SALARY_CREATE', $user);
             if ($result < 0) {
                 $error++;
             }
             // End call triggers
         } else {
             $error++;
         }
         if (!$error) {
             $this->db->commit();
             return $this->id;
         } else {
             $this->db->rollback();
             return -2;
         }
     } else {
         $this->error = $this->db->error();
         $this->db->rollback();
         return -1;
     }
 }
 /**
  *      Add 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	$user               Object of user making payment
  *      @param  string	$mode               'payment_expensereport'
  *      @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
  *      @return int                 		<0 if KO, >0 if OK
  */
 function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
 {
     global $langs, $conf;
     $error = 0;
     if (!empty($conf->banque->enabled)) {
         require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php';
         $acc = new Account($this->db);
         $acc->fetch($accountid);
         $total = $this->total;
         if ($mode == 'payment_expensereport') {
             $amount = $total;
         }
         // Insert payment into llx_bank
         $bank_line_id = $acc->addline($this->datepaid, $this->fk_typepayment, $label, -$amount, $this->num_payment, '', $user, $emetteur_nom, $emetteur_banque);
         // Update fk_bank in 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', 'payment_expensereport' in bank_url between payment and bank transaction
             $url = '';
             if ($mode == 'payment_expensereport') {
                 $url = DOL_URL_ROOT . '/expensereport/payment/card.php?rowid=';
             }
             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 'user' in bank_url between user and bank transaction
             if (!$error) {
                 foreach ($this->amounts as $key => $value) {
                     if ($mode == 'payment_expensereport') {
                         $euser = new User($this->db);
                         $euser->fetch($key);
                         $result = $acc->add_url_line($bank_line_id, $euser->id, DOL_URL_ROOT . '/user/card.php?id=', $euser->getFullName($langs), 'user');
                         if ($result <= 0) {
                             $this->error = $this->db->lasterror();
                             dol_syslog(get_class($this) . '::addPaymentToBank ' . $this->error);
                             $error++;
                         }
                     }
                 }
             }
         } else {
             $this->error = $acc->error;
             $error++;
         }
     }
     if (!$error) {
         return 1;
     } else {
         return -1;
     }
 }
 /**
  *  Create in database
  *
  *	@param	User	$user		Object user that insert
  *	@return	int					<0 if KO, rowid in tva table if OK
  */
 function addPayment($user)
 {
     global $conf, $langs;
     $this->db->begin();
     // Clean parameters
     $this->amount = price2num(trim($this->amount));
     $this->label = trim($this->label);
     $this->note = trim($this->note);
     $this->fk_bank = trim($this->fk_bank);
     $this->fk_user_creat = trim($this->fk_user_creat);
     $this->fk_user_modif = trim($this->fk_user_modif);
     // Check parameters
     if (!$this->label) {
         $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label"));
         return -3;
     }
     if ($this->amount < 0 || $this->amount == '') {
         $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount"));
         return -4;
     }
     if (!empty($conf->banque->enabled) && (empty($this->accountid) || $this->accountid <= 0)) {
         $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Account"));
         return -5;
     }
     if (!empty($conf->banque->enabled) && (empty($this->type_payment) || $this->type_payment <= 0)) {
         $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode"));
         return -5;
     }
     // Insert into llx_tva
     $sql = "INSERT INTO " . MAIN_DB_PREFIX . "tva (datep";
     $sql .= ", datev";
     $sql .= ", amount";
     $sql .= ", fk_typepayment";
     $sql .= ", num_payment";
     if ($this->note) {
         $sql .= ", note";
     }
     if ($this->label) {
         $sql .= ", label";
     }
     $sql .= ", fk_user_creat";
     $sql .= ", fk_bank";
     $sql .= ", entity";
     $sql .= ") ";
     $sql .= " VALUES (";
     $sql .= "'" . $this->db->idate($this->datep) . "'";
     $sql .= ", '" . $this->db->idate($this->datev) . "'";
     $sql .= ", " . $this->amount;
     $sql .= ", '" . $this->type_payment . "'";
     $sql .= ", '" . $this->num_payment . "'";
     if ($this->note) {
         $sql .= ", '" . $this->db->escape($this->note) . "'";
     }
     if ($this->label) {
         $sql .= ", '" . $this->db->escape($this->label) . "'";
     }
     $sql .= ", '" . $user->id . "'";
     $sql .= ", NULL";
     $sql .= ", " . $conf->entity;
     $sql .= ")";
     dol_syslog(get_class($this) . "::addPayment sql=" . $sql);
     $result = $this->db->query($sql);
     if ($result) {
         $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "tva");
         // TODO should be called paiementtva
         // Start triggers
         include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
         $interface = new Interfaces($this->db);
         $result = $interface->run_triggers('TVA_ADDPAYMENT', $this, $user, $langs, $conf);
         if ($result < 0) {
             $error++;
             $this->errors = $interface->errors;
         }
         // End triggers
         if ($this->id > 0) {
             $ok = 1;
             if (!empty($conf->banque->enabled) && !empty($this->amount)) {
                 // Insert into llx_bank
                 require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php';
                 $acc = new Account($this->db);
                 $result = $acc->fetch($this->accountid);
                 if ($result <= 0) {
                     dol_print_error($this->db);
                 }
                 $bank_line_id = $acc->addline($this->datep, $this->type_payment, $this->label, -abs($this->amount), '', '', $user);
                 // Update fk_bank into llx_tva. So we know vat line used to generate bank transaction
                 if ($bank_line_id > 0) {
                     $this->update_fk_bank($bank_line_id);
                 } else {
                     $this->error = $acc->error;
                     $ok = 0;
                 }
                 // Update links
                 $result = $acc->add_url_line($bank_line_id, $this->id, DOL_URL_ROOT . '/compta/tva/fiche.php?id=', "(VATPayment)", "payment_vat");
                 if ($result < 0) {
                     $this->error = $acc->error;
                     $ok = 0;
                 }
             }
             if ($ok) {
                 $this->db->commit();
                 return $this->id;
             } else {
                 $this->db->rollback();
                 return -3;
             }
         } else {
             $this->error = $this->db->error();
             $this->db->rollback();
             return -2;
         }
     } else {
         $this->error = $this->db->error();
         $this->db->rollback();
         return -1;
     }
 }
 /**
  *      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, $socid, $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, $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) {
                     if ($mode == 'payment') {
                         $fac = new Ticket($this->db);
                         $fac->fetch($key);
                         $fac->fetch_thirdparty();
                         if (!in_array($socid, $linkaddedforthirdparty)) {
                             $thirdparty = new Societe($this->db);
                             $thirdparty->fetch($socid);
                             $result = $acc->add_url_line($bank_line_id, $socid, DOL_URL_ROOT . '/comm/fiche.php?socid=', $thirdparty->nom, 'company');
                             if ($result <= 0) {
                                 dol_print_error($this->db);
                             }
                             $linkaddedforthirdparty[$fac->thirdparty->id] = $socid;
                             // 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;
     }
 }
Beispiel #13
0
    if (!$operation) {
        $mesg = $langs->trans("ErrorFieldRequired", $langs->trans("Type"));
    }
    if (!$amount) {
        $mesg = $langs->trans("ErrorFieldRequired", $langs->trans("Amount"));
    }
    if (!$centro) {
        $mesg = $langs->trans("ErrorFieldRequired", $langs->trans("centro"));
    }
    if (!$subcentro) {
        $mesg = $langs->trans("ErrorFieldRequired", $langs->trans("subcentro"));
    }
    if (!$mesg) {
        $acct = new Account($db);
        $acct->fetch($account);
        $insertid = $acct->addline($dateop, $operation, $label, $amount, $num_chq, $cat1, $user, '', '', $centro, $subcentro);
        //adicionado o $origem para o kurt
        if ($insertid > 0) {
            Header("Location: account.php?account=" . $account . "&action=addline&cancel=cancelar");
            exit;
        } else {
            dol_print_error($db, $acct->error);
        }
    } else {
        $action = 'addline';
    }
}
if ($action == 'confirm_delete' && $_POST["confirm"] == 'yes' && $user->rights->banque->modifier) {
    $accline = new AccountLine($db);
    $accline->fetch($_GET["rowid"]);
    $result = $accline->delete();