Exemplo n.º 1
0
function select()
{
    $credit = new credit();
    if (isset($_GET['page'])) {
        $pages = $_GET['page'];
    } else {
        $pages = 1;
    }
    $GLOBALS['pages'] = $pages;
    $page = new page($pages);
    $GLOBALS['page'] = $page;
    //$rs =$credit->queryCredit();
    $total = $credit->countCredit();
    //$totle =mysql_num_rows($rs);
    $GLOBALS['page']->pageft($total, $GLOBALS['displaypg']);
    $item = $credit->queryCredit();
    global $smarty;
    $smarty->assign("item", $item);
    $smarty->assign("obj", $credit);
    $smarty->assign("nextpage", $GLOBALS['page']->getPagenav());
}
Exemplo n.º 2
0
function _updatemembercount($uids, $dataarr = array(), $checkgroup = true, $operation = '', $relatedid = 0, $ruletxt = '')
{
    if (empty($uids)) {
        return;
    }
    if (!is_array($dataarr) || empty($dataarr)) {
        return;
    }
    if ($operation && $relatedid) {
        $writelog = true;
        $log = array('uid' => $uids, 'operation' => $operation, 'relatedid' => $relatedid, 'dateline' => time());
    } else {
        $writelog = false;
    }
    $data = array();
    foreach ($dataarr as $key => $val) {
        if (empty($val)) {
            continue;
        }
        $val = intval($val);
        $id = intval($key);
        $id = !$id && substr($key, 0, -1) == 'extcredits' ? intval(substr($key, -1, 1)) : $id;
        if (0 < $id && $id < 9) {
            $data['extcredits' . $id] = $val;
            if ($writelog) {
                $log['extcredits' . $id] = $val;
            }
        } else {
            $data[$key] = $val;
        }
    }
    if ($writelog) {
        DB::insert('common_credit_log', $log);
    }
    if ($data) {
        include_once libfile('class/credit');
        $credit =& credit::instance();
        $credit->updatemembercount($data, $uids, $checkgroup, $ruletxt);
    }
}
Exemplo n.º 3
0
function checkusergroup($uid = 0)
{
    $credit =& credit::instance();
    $credit->checkusergroup($uid);
}
Exemplo n.º 4
0
 function action_update_total()
 {
     log_debug("invoice_items", "Executing action_update_total()");
     // default values
     $amount = "0";
     $amount_tax = "0";
     $amount_total = "0";
     /*
     	Total up all the items, and all the tax
     */
     $amount = 0;
     $amount_tax = 0;
     $amount_paid = 0;
     // fetch item amounts from DB
     $sql_obj = new sql_query();
     $sql_obj->string = "SELECT amount, type FROM `account_items` WHERE invoicetype='" . $this->type_invoice . "' AND invoiceid='" . $this->id_invoice . "'";
     $sql_obj->execute();
     if ($sql_obj->num_rows()) {
         $sql_obj->fetch_array();
         foreach ($sql_obj->data as $data_sql) {
             // total up the different item types
             if ($data_sql["type"] != "tax" && $data_sql["type"] != "payment") {
                 $amount += $data_sql["amount"];
             }
             if ($data_sql["type"] == "tax") {
                 $amount_tax += $data_sql["amount"];
             }
             if ($data_sql["type"] == "payment") {
                 $amount_paid += $data_sql["amount"];
             }
         }
     }
     // final totals
     $amount_total = $amount + $amount_tax;
     $amount = sprintf("%0.2f", $amount);
     $amount_tax = sprintf("%0.2f", $amount_tax);
     $amount_total = sprintf("%0.2f", $amount_total);
     $amount_paid = sprintf("%0.2f", $amount_paid);
     /*
     	Update the invoice
     */
     $sql_obj = new sql_query();
     if ($this->type_invoice == "quotes" || $this->type_invoice == "ar_credit" || $this->type_invoice == "ar_credit") {
         $sql_obj->string = "UPDATE `account_" . $this->type_invoice . "` SET " . "amount='" . $amount . "', " . "amount_tax='" . $amount_tax . "', " . "amount_total='" . $amount_total . "' " . "WHERE id='" . $this->id_invoice . "' LIMIT 1";
     } else {
         $sql_obj->string = "UPDATE `account_" . $this->type_invoice . "` SET " . "amount='" . $amount . "', " . "amount_tax='" . $amount_tax . "', " . "amount_total='" . $amount_total . "', " . "amount_paid='" . $amount_paid . "' " . "WHERE id='" . $this->id_invoice . "' LIMIT 1";
     }
     if (!$sql_obj->execute()) {
         log_debug("invoice_items", "A fatal SQL error occured whilst attempting to update invoice totals");
         return 0;
     }
     /*
     	Update the credit (if any)
     */
     if ($this->type_invoice == "ar_credit" || $this->type_invoice == "ap_credit") {
         $credit = new credit();
         $credit->id = $this->id_invoice;
         $credit->type = $this->type_invoice;
         $credit->load_data();
         $credit->action_update_balance();
     }
     return 1;
 }
Exemplo n.º 5
0
function checkusergroup($uid = 0)
{
    include_once libfile('class/credit');
    $credit =& credit::instance();
    $credit->checkusergroup($uid);
}
function credit_form_lock_process($type, $returnpage_error, $returnpage_success)
{
    log_debug("inc_credits_forms", "Executing credit_form_lock_process({$type}, {$mode}, {$returnpage_error}, {$returnpage_success})");
    $credit = new credit();
    $credit->type = $type;
    /*
    	Import POST Data
    */
    $credit->id = @security_form_input_predefined("int", "id_credit", 1, "");
    $data["lock_credit"] = @security_form_input_predefined("checkbox", "lock_credit", 0, "");
    /*
    	Error Handling
    */
    // make sure the credit actually exists
    if (!$credit->verify_credit()) {
        log_write("error", "process", "The credit note you have attempted to delete - " . $credit->id . " - does not exist in this system.");
    }
    // check if credit is locked or not
    if ($credit->check_lock()) {
        log_write("error", "process", "The credit note can not be locked because it is *already* locked.");
    }
    // check lock
    if (!$data["lock_credit"]) {
        log_write("error", "process", "You must check to confirm the credit note lock.");
    }
    // return to input page in event of an error
    if ($_SESSION["error"]["message"]) {
        $_SESSION["error"]["form"][$type . "_credit_lock"] = "failed";
        header("Location: ../../index.php?page={$returnpage_error}&id=" . $credit->id);
        exit(0);
    }
    /*
    	Lock Credit Note
    */
    $credit->load_data();
    if ($credit->action_lock()) {
        log_write("notification", "process", "The selected credit note has now been locked.");
    } else {
        log_write("error", "process", "An error occured whilst attempting to lock the credit note.");
    }
    // display updated details
    header("Location: ../../index.php?page={$returnpage_success}&id=" . $credit->id);
    exit(0);
}
Exemplo n.º 7
0
     }
     if ($fid) {
         $fids = $globalrule['fids'] ? explode(',', $globalrule['fids']) : array();
         if ($havecredit) {
             $rule['rid'] = $rid;
             $rule['fid'] = $fid;
             $rule['rulename'] = $ruleinfo['rulename'];
             $rule['action'] = $ruleinfo['action'];
             $policy[$ruleinfo['action']] = $rule;
             if (!in_array($fid, $fids)) {
                 $fids[] = $fid;
             }
         } else {
             if ($rule['cycletype'] != 0 && ($rule['cycletype'] == 4 && !$rule['rewardnum'])) {
                 require_once DISCUZ_ROOT . './source/class/class_credit.php';
                 credit::deletelogbyfid($rid, $fid);
             }
             unset($policy[$ruleinfo['action']]);
             if (in_array($fid, $fids)) {
                 unset($fids[array_search($fid, $fids)]);
             }
         }
         DB::update('forum_forumfield', array('creditspolicy' => addslashes(serialize($policy))), array('fid' => $fid));
         DB::update('common_credit_rule', array('fids' => implode(',', $fids)), array('rid' => $rid));
         updatecache('creditrule');
         cpmsg('credits_update_succeed', 'action=forums&operation=edit&anchor=credits&fid=' . $fid, 'succeed');
     } else {
         DB::update('common_credit_rule', $rule, array('rid' => $rid));
     }
     updatecache('creditrule');
 } else {
Exemplo n.º 8
0
        }
        $allcredit = $invitenum * $creditnum;
        if ($space[$creditkey] < $allcredit) {
            showmessage('mail_credit_inadequate', $baseurl, array(), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true));
        }
        $havecode = false;
        $dateline = $_G['timestamp'];
        for ($i = 0; $i < $invitenum; $i++) {
            $code = strtolower(random(6));
            $havecode = true;
            $invitedata = array('uid' => $_G['uid'], 'code' => $code, 'dateline' => $dateline, 'endtime' => $_G['group']['maxinviteday'] ? $_G['timestamp'] + $_G['group']['maxinviteday'] * 24 * 3600 : 0, 'inviteip' => $_G['clientip']);
            C::t('common_invite')->insert($invitedata);
        }
        if ($havecode) {
            require_once libfile('class/credit');
            $creditobj = new credit();
            $creditobj->updatemembercount(array($creditkey => 0 - $allcredit), $_G['uid']);
        }
        showmessage('do_success', $baseurl, array('deduction' => $allcredit, 'dateline' => $dateline), array('showdialog' => 1, 'showmsg' => true, 'closetime' => true, 'return' => false));
    }
}
if ($_GET['op'] == 'resend') {
    $id = $_GET['id'] ? intval($_GET['id']) : 0;
    if (submitcheck('resendsubmit')) {
        if (empty($id)) {
            showmessage('send_result_resend_error', $baseurl);
        }
        if ($value = C::t('common_invite')->fetch_by_id_uid($id, $_G['uid'])) {
            if ($creditnum) {
                $inviteurl = getinviteurl($value['id'], $value['code'], $value['appid']);
            }
Exemplo n.º 9
0
 function get_credit_pdf($id, $credittype)
 {
     log_debug('invoices_manage_soap', "Executing get_creditnote_pdf({$id}, {$credittype})");
     // check the credit type
     if ($credittype != 'ar' && $credittype != 'ap') {
         throw new SoapFault('Sender', 'INVALID_CREDIT_TYPE');
     }
     if (user_permissions_get('accounts_' . $credittype . '_view')) {
         $obj_credit = new credit();
         $obj_credit->type = $credittype;
         // sanitise input
         $obj_credit->id = @security_script_input_predefined('int', $id);
         if (!$obj_credit->id || $obj_credit->id == 'error') {
             throw new SoapFault('Sender', 'INVALID_INPUT');
         }
         // load data from DB for this credit note
         if (!$obj_credit->load_data()) {
             throw new SoapFault('Sender', 'UNEXPECTED_ACTION_ERROR');
         }
         // generate PDF
         $obj_credit->generate_pdf();
         // return data
         return base64_encode($obj_credit->obj_pdf->output);
     } else {
         throw new SoapFault('Sender', 'ACCESS_DENIED');
     }
 }
function page_execute($argv)
{
    /*
    	Input Options
    */
    $option_date = NULL;
    $option_type = NULL;
    if (empty($argv[2])) {
        die("You must provide a date option in form of YYYY-MM-DD\n");
    }
    if (preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/', $argv[2])) {
        $option_date = $argv[2];
    } else {
        die("You must provide a date option in form of YYYY-MM-DD - wrong format supplied\n");
    }
    if (empty($argv[3])) {
        die("Service Type must be set.\n");
    }
    if (preg_match('/^\\S\\S*$/', $argv[3])) {
        $option_type = $argv[3];
        $option_type_id = sql_get_singlevalue("SELECT id as value FROM service_types WHERE name='{$option_type}' LIMIT 1");
        if (!$option_type_id) {
            die("Service type {$option_type} is unknown\n");
        }
    } else {
        die("You must provide a service type\n");
    }
    log_write("notification", "repair", "Executing usage charge rollback for invoices generated {$option_date} for service type {$option_type} (ID {$option_type_id})");
    /*
    	Fetch IDs of all sercices with selected option type
    */
    $option_services = array();
    $obj_sql_service = new sql_query();
    $obj_sql_service->string = "SELECT id FROM services WHERE typeid='" . $option_type_id . "'";
    $obj_sql_service->execute();
    if ($obj_sql_service->num_rows()) {
        $obj_sql_service->fetch_array();
        foreach ($obj_sql_service->data as $data) {
            $option_services[] = $data["id"];
        }
    }
    unset($obj_sql_service);
    log_write("notification", "repair", "Returned ID of matching services, array of " . format_arraytocommastring($option_services, NULL) . "");
    /*
    	Start Transaction
    */
    $obj_sql_trans = new sql_query();
    $obj_sql_trans->trans_begin();
    /*
    	Fetch AR Invoices for selected period
    */
    $obj_sql_ar = new sql_query();
    $obj_sql_ar->string = "SELECT id, customerid, code_invoice, dest_account, amount_total, amount_paid FROM account_ar WHERE date_trans='{$option_date}'";
    $obj_sql_ar->execute();
    if ($obj_sql_ar->num_rows()) {
        $obj_sql_ar->fetch_array();
        foreach ($obj_sql_ar->data as $data_ar) {
            $invoice_items = array();
            // store item details
            /*
            	Fetch Invoice Items
            */
            $obj_sql_items = new sql_query();
            $obj_sql_items->string = "SELECT id, customid, chartid, amount, description FROM account_items WHERE invoiceid='" . $data_ar["id"] . "' AND invoicetype='ar' AND type='service_usage'";
            $obj_sql_items->execute();
            if ($obj_sql_items->num_rows()) {
                $obj_sql_items->fetch_array();
                /*
                	For each item, check the service type and whether it is one of the items
                	that we want to credit.
                */
                foreach ($obj_sql_items->data as $data_item) {
                    if (in_array($data_item["customid"], $option_services)) {
                        // item is one of the target services, add details to array
                        log_write("debug", "repair", "Invoice ID #" . $data_ar["id"] . ", (" . $data_ar["code_invoice"] . ") item ID #" . $data_item["id"] . " is a valid service usage item to refund.");
                        // check if it's call charges
                        if (!strpos($data_item["description"], "call charges")) {
                            log_write("debug", "repair", "Skipping non-call charge usage item from credit");
                            continue;
                        }
                        // add invoice items
                        $invoice_items_tmp = array();
                        $invoice_items_tmp["id"] = $data_item["id"];
                        $invoice_items_tmp["customid"] = $data_item["customid"];
                        $invoice_items_tmp["chartid"] = $data_item["chartid"];
                        $invoice_items_tmp["amount"] = $data_item["amount"];
                        $invoice_items_tmp["description"] = $data_item["description"];
                        // add to array
                        $invoice_items[] = $invoice_items_tmp;
                    }
                }
            }
            // end of AR invoice items loop
            /*
            	If any items matched, we should create a credit note and add the items as credits
            */
            if (!empty($invoice_items)) {
                /*
                	Create Credit Note
                
                	We have all the information needed for the credit note from the invoice.
                */
                $credit = new credit();
                $credit->type = "ar_credit";
                $credit->prepare_set_defaults();
                $credit->data["invoiceid"] = $data_ar["id"];
                $credit->data["customerid"] = $data_ar["customerid"];
                $credit->data["employeeid"] = "0";
                $credit->data["date_trans"] = date("Y-m-d");
                $credit->data["dest_account"] = $data_ar["dest_account"];
                $credit->data["notes"] = "Automatically generated credit by repair process to cover service usage refund of invoice " . $data_ar["code_invoice"] . "";
                // create a new credit
                if ($credit->action_create()) {
                    log_write("notification", "repair", "Credit note successfully created");
                    journal_quickadd_event("account_ar_credit", $credit->id, "Credit Note successfully created");
                } else {
                    log_write("error", "repair", "An unexpected fault occured whilst attempting to create the credit note");
                }
                /*
                	Add Items
                
                	We loop through each selected item and for each item, we create an appropiate credit note item.
                */
                foreach ($invoice_items as $data_item) {
                    // create credit item
                    $item = new invoice_items();
                    $item->id_invoice = $credit->id;
                    $item->type_invoice = "ar_credit";
                    $item->type_item = "credit";
                    // set item details
                    $data = array();
                    $data["amount"] = $data_item["amount"];
                    $data["price"] = $data_item["amount"];
                    $data["chartid"] = $data_item["chartid"];
                    $data["description"] = "Credit For: " . $data_item["description"];
                    // fetch taxes for selected item
                    $sql_tax_obj = new sql_query();
                    $sql_tax_obj->string = "SELECT taxid FROM services_taxes WHERE serviceid='" . $data_item["customid"] . "'";
                    $sql_tax_obj->execute();
                    if ($sql_tax_obj->num_rows()) {
                        $sql_tax_obj->fetch_array();
                        foreach ($sql_tax_obj->data as $data_tax) {
                            $sql_cust_tax_obj = new sql_query();
                            $sql_cust_tax_obj->string = "SELECT id FROM customers_taxes WHERE customerid='" . $credit->data["customerid"] . "' AND taxid='" . $data_tax["taxid"] . "'";
                            $sql_cust_tax_obj->execute();
                            if ($sql_cust_tax_obj->num_rows()) {
                                $data["tax_" . $data_tax["taxid"]] = "on";
                            }
                        }
                    }
                    unset($sql_tax_obj);
                    if (!$item->prepare_data($data)) {
                        log_write("error", "process", "An error was encountered whilst processing supplied data.");
                    } else {
                        $item->action_create();
                        $item->action_update();
                    }
                    unset($data);
                }
                // end of items loop
                /*
                	Re-calculate Credit Note Totals
                */
                $item->action_update_tax();
                $item->action_update_total();
                $item->action_update_ledger();
                // finsihed with credit items
                unset($item);
                /*
                	Apply Credit Note against the invoice if it hasn't been paid in full.
                */
                $amount_invoice = array();
                if ($data_ar["amount_total"] != $data_ar["amount_paid"]) {
                    // determine amount owing
                    $amount_invoice["owing"] = $data_ar["amount_total"] - $data_ar["amount_paid"];
                    if ($amount_invoice["owing"] <= 0) {
                        // nothing todo
                        log_write("notification", "repair", "Ignoring overpaid invoice " . $data_ar["code_invoice"] . " and assigning credit note to customer account/pool instead");
                    } else {
                        // determine credit amount
                        $amount_invoice["credit"] = sql_get_singlevalue("SELECT amount_total as value FROM account_ar_credit WHERE id='" . $credit->id . "' LIMIT 1");
                        if ($amount_invoice["credit"] > $amount_invoice["owing"]) {
                            // pay the amount owing which is less than the credit
                            $amount_invoice["creditpay"] = $amount_invoice["owing"];
                        } else {
                            // customer owes more than the credit is for, make credit payment amount maximum
                            $amount_invoice["creditpay"] = $amount_invoice["credit"];
                        }
                        // make credit payment against the invoice
                        $item = new invoice_items();
                        $item->id_invoice = $data_ar["id"];
                        $item->type_invoice = "ar";
                        $item->type_item = "payment";
                        // set item details
                        $data = array();
                        $data["date_trans"] = date("Y-m-d");
                        $data["amount"] = $amount_invoice["creditpay"];
                        $data["chartid"] = "credit";
                        $data["source"] = "CREDITED FUNDS (AUTOMATIC)";
                        $data["description"] = "Credit from credit note " . $credit->data["code_credit"] . " for service usage charge correction";
                        if (!$item->prepare_data($data)) {
                            log_write("error", "process", "An error was encountered whilst processing supplied data for credit payment to invoice");
                        } else {
                            // create & update payment item
                            $item->action_create();
                            $item->action_update();
                            // update invoice totals & ledger
                            $item->action_update_tax();
                            $item->action_update_total();
                            $item->action_update_ledger();
                            log_write("notification", "repair", "Applied credit of " . $amount_invoice["creditpay"] . "");
                        }
                        unset($item);
                    }
                    // end if credit payment made
                } else {
                    log_write("notification", "repair", "Credited invoice " . $data_ar["code_invoice"] . " has already been paid in full, assigning credit note to customer's credit pool for future use.");
                }
                /*
                	Email PDF credit notes and message.
                */
                if ($GLOBALS["config"]["ACCOUNTS_INVOICE_AUTOEMAIL"] == 1 || $GLOBALS["config"]["ACCOUNTS_INVOICE_AUTOEMAIL"] == "enabled") {
                    $email = $credit->generate_email();
                    $credit->email_credit($email["sender"], $email["to"], $email["cc"], $email["bcc"], $email["subject"], $email["message"]);
                } else {
                    log_write("notification", "repair", "No credit note email sent, ACCOUNTS_INVOICE_AUTOEMAIL is disabled.");
                }
                // unset the credit note
                unset($credit);
                /*
                	Flag the refunded usage periods for re-billing.
                
                	Now that we have refunded the usage on the selected invoice, we should then flag any service periods
                	of the same service type and invoice ID, to cause the usge to be rebilled in the next service billing month.
                */
                // fetch id_service_customer values from services where customer matches invoice
                $obj_sql_cust = new sql_query();
                $obj_sql_cust->string = "SELECT id FROM services_customers WHERE customerid='" . $data_ar["customerid"] . "' AND serviceid IN (" . format_arraytocommastring($option_services, NULL) . ")";
                $obj_sql_cust->execute();
                if ($obj_sql_cust->num_rows()) {
                    $obj_sql_cust->fetch_array();
                    foreach ($obj_sql_cust->data as $data_cust) {
                        // update any periods for this customer-service which have the ID of the selected invoice as
                        // the usage period invoice.
                        //
                        // these usage periods will then be re-invoiced at the next service invoicing run.
                        //
                        $obj_sql_period = new sql_query();
                        $obj_sql_period->string = "UPDATE services_customers_periods SET invoiceid_usage='0', rebill='1' WHERE invoiceid_usage='" . $data_ar["id"] . "' AND id_service_customer='" . $data_cust["id"] . "'";
                        $obj_sql_period->execute();
                    }
                    log_write("notification", "repair", "Flagged services for customer " . $data_ar["customerid"] . " to bill for usage periods.");
                } else {
                    log_write("warning", "repair", "No usage periods found to flag for rebilling for customer " . $data_ar["customerid"] . ", possibly the service has been deleted?");
                }
                unset($obj_sql_cust);
            }
            // if creditable items exist on the selected invoice
            if (error_check()) {
                // there was an error, do not continue processing invoices.
                continue;
            }
        }
    }
    // end of AR invoice loop
    /*
    	Close Transaction
    */
    if (error_check()) {
        // rollback/failure
        log_write("error", "repair", "An error occured whilst executing, rolling back DB changes");
        $obj_sql_trans->trans_rollback();
    } else {
        // commit
        log_write("notification", "repair", "Successful execution, applying DB changes");
        $obj_sql_trans->trans_commit();
    }
}
Exemplo n.º 11
0
 function execute()
 {
     log_debug("credit_form_export", "Executing execute()");
     /*
     	Fetch basic credit details
     */
     $obj_sql_credit = new sql_query();
     $obj_sql_credit->string = "SELECT code_credit, customerid FROM account_" . $this->type . " WHERE id='" . $this->credit_id . "' LIMIT 1";
     $obj_sql_credit->execute();
     $obj_sql_credit->fetch_array();
     /*
     	Generate Email
     
     	This function call provides us with all the email fields we can use to complete the form with.
     */
     $obj_credit = new credit();
     $obj_credit->type = $this->type;
     $obj_credit->id = $this->credit_id;
     $email = $obj_credit->generate_email();
     /*
     	Define email form
     */
     $this->obj_form_email = new form_input();
     $this->obj_form_email->formname = "credit_export_email";
     $this->obj_form_email->language = $_SESSION["user"]["lang"];
     $this->obj_form_email->action = $this->processpage;
     $this->obj_form_email->method = "post";
     // general
     $structure = NULL;
     $structure["fieldname"] = "sender";
     $structure["type"] = "radio";
     $structure["defaultvalue"] = $email["sender"];
     $structure["values"] = array("system", "user");
     $structure["translations"]["system"] = sql_get_singlevalue("SELECT value FROM config WHERE name='COMPANY_NAME'") . " &lt;" . sql_get_singlevalue("SELECT value FROM config WHERE name='COMPANY_CONTACT_EMAIL'") . "&gt;";
     $structure["translations"]["user"] = user_information("realname") . " &lt;" . user_information("contact_email") . "&gt;";
     $this->obj_form_email->add_input($structure);
     $structure = NULL;
     $structure["fieldname"] = "subject";
     $structure["type"] = "input";
     $structure["defaultvalue"] = $email["subject"];
     $structure["options"]["width"] = "600";
     $this->obj_form_email->add_input($structure);
     $structure = NULL;
     $structure["fieldname"] = "email_to";
     $structure["type"] = "input";
     $structure["defaultvalue"] = $email["to"];
     $structure["options"]["width"] = "600";
     $this->obj_form_email->add_input($structure);
     $structure = NULL;
     $structure["fieldname"] = "email_cc";
     $structure["type"] = "input";
     $structure["defaultvalue"] = $email["cc"];
     $structure["options"]["width"] = "600";
     $this->obj_form_email->add_input($structure);
     $structure = NULL;
     $structure["fieldname"] = "email_bcc";
     $structure["type"] = "input";
     $structure["defaultvalue"] = $email["bcc"];
     $structure["options"]["width"] = "600";
     $this->obj_form_email->add_input($structure);
     $structure = NULL;
     $structure["fieldname"] = "email_message";
     $structure["type"] = "textarea";
     $structure["defaultvalue"] = $email["message"];
     $structure["options"]["width"] = "600";
     $structure["options"]["height"] = "100";
     $this->obj_form_email->add_input($structure);
     // hidden
     $structure = NULL;
     $structure["fieldname"] = "formname";
     $structure["type"] = "hidden";
     $structure["defaultvalue"] = $this->obj_form_email->formname;
     $this->obj_form_email->add_input($structure);
     $structure = NULL;
     $structure["fieldname"] = "id_credit";
     $structure["type"] = "hidden";
     $structure["defaultvalue"] = $this->credit_id;
     $this->obj_form_email->add_input($structure);
     // submit button
     $structure = NULL;
     $structure["fieldname"] = "submit";
     $structure["type"] = "submit";
     $structure["defaultvalue"] = "Send via Email";
     $this->obj_form_email->add_input($structure);
     // load any data returned due to errors
     $this->obj_form_email->load_data_error();
     /*
     	Define download form
     */
     $this->obj_form_download = new form_input();
     $this->obj_form_download->formname = "credit_export_download";
     $this->obj_form_download->language = $_SESSION["user"]["lang"];
     $this->obj_form_download->action = $this->processpage;
     $this->obj_form_download->method = "post";
     // general
     $structure = NULL;
     $structure["fieldname"] = "credit_mark_as_sent";
     $structure["type"] = "checkbox";
     $structure["options"]["label"] = "Check this to show that the credit has been sent to the customer when you download the PDF";
     $this->obj_form_download->add_input($structure);
     // hidden
     $structure = NULL;
     $structure["fieldname"] = "formname";
     $structure["type"] = "hidden";
     $structure["defaultvalue"] = $this->obj_form_download->formname;
     $this->obj_form_download->add_input($structure);
     $structure = NULL;
     $structure["fieldname"] = "id_credit";
     $structure["type"] = "hidden";
     $structure["defaultvalue"] = $this->credit_id;
     $this->obj_form_download->add_input($structure);
     // submit button
     $structure = NULL;
     $structure["fieldname"] = "submit";
     $structure["type"] = "submit";
     $structure["defaultvalue"] = "Download as PDF";
     $this->obj_form_download->add_input($structure);
     // load any data returned due to errors
     $this->obj_form_download->load_data_error();
     return 1;
 }