Esempio n. 1
0
 public function viewInvoiceDetails($invoiceId)
 {
     try {
         $invoice = Invoice::get($invoiceId);
         ///
         $allTools = Tool::getAll();
         // $invoice->items // this is an array of Item Objects
         return view("/invoiceDetails", ["invoice" => $invoice, "tools" => $allTools]);
     } catch (PDOException $e) {
         die($e->getMessage());
     }
 }
Esempio n. 2
0
 /**
  * 
  * @param int $invoiceMapId
  * @return \ifirma\SendResult
  */
 private function _sendInvoiceBasedOnProforma($invoiceMapId)
 {
     $invoiceMap = InvoiceMap::get($invoiceMapId);
     if ($invoiceMap === null) {
         return SendResult::makeInvalidResponse(SendResult::MESSAGE_MISSING_INVOICE_PROFORMA);
     }
     $invoiceResponseObj = $this->_getInvoiceResponseObject($invoiceMap);
     if ($invoiceResponseObj === null) {
         return SendResult::makeInvalidResponse(SendResult::MESSAGE_MISSING_INVOICE_PROFORMA);
     }
     $sendInvoiceResult = $invoiceResponseObj->sendInvoiceBasedOnThisProforma();
     if (!$sendInvoiceResult->isOk()) {
         return SendResult::makeInvalidResponse($sendInvoiceResult->getMessage() !== '' ? $sendInvoiceResult->getMessage() : SendResult::MESSAGE_UNABLE_TO_SEND_INVOICE);
     }
     $sendInvoiceResultContent = $sendInvoiceResult->getContent();
     $newInvoiceId = $sendInvoiceResultContent[Response::KEY_INVOICE_ID];
     $newInvoiceMapObj = $this->_createAndSaveInvoiceMapObject($newInvoiceId, $invoiceMap->{InvoiceMap::COLUMN_NAME_ORDER_ID}, InvoiceMap::INVOICE_TYPE_NORMAL);
     $newInvoiceObj = Invoice::get($newInvoiceId);
     $newInvoiceMapObj->updateInvoiceNumber(Invoice::filterNumber($newInvoiceObj->{InvoiceResponse::KEY_PELNY_NUMER}));
     return SendResult::makeValidResponse($sendInvoiceResult->getMessage() !== '' ? $sendInvoiceResult->getMessage() : SendResult::MESSAGE_INVOICE_SUCCESSFULLY_SEND);
 }
Esempio n. 3
0
</p><p style="font-weight: bold;">Add an item... </p><p><?php 
if (Invoice::add_item($id, 270.98, 23, 'some references')) {
    print_array(Invoice::get_items_of($id));
} else {
    echo "failed";
    exit;
}
?>
</p><p style="font-weight: bold;">Add another item... </p><p><?php 
if (Invoice::add_item($id, 0.05, 93, 'some other charges')) {
    print_array(Invoice::get_items_of($id));
} else {
    echo "failed";
    exit;
}
?>
</p><p style="font-weight: bold;">Pay an invoice... </p><p><?php 
$data = array();
$data['id'] = $id;
$data['paid_on'] = sql_date_add(today(), 30, 'day');
$data['paid_through'] = 'CHQ';
$data['paid_id'] = 'a_cheque_number';
if (Invoice::update($data)) {
    print_array(Invoice::get($id));
} else {
    echo "failed";
    exit;
}
?>
</p>
 public function calculate(Invoice $invoice, InvoiceItem $item, User $aff, $paymentNumber = 0, $tier = 0, $paymentAmount = 0.0, $paymentDate = 'now')
 {
     // take aff.commission_days in account for 1-tier only
     if ($tier == 0 && ($commissionDays = $this->getDi()->config->get('aff.commission_days'))) {
         $signupDays = $this->getDi()->time - strtotime($invoice->getUser()->added);
         $signupDays = intval($signupDays / 3600 * 24);
         // to days
         if ($commissionDays < $signupDays) {
             return;
         }
         // no commission for this case, affiliate<->user relation is expired
         // however, the relation still works for 2-level commissions
     }
     $multi = 1.0;
     $prefix = $paymentNumber == 0 ? 'first' : 'second';
     if ($tier == 0) {
         if ($invoice->get("{$prefix}_total") == 0) {
             $paidForItem = 0;
         } else {
             $paidForItem = $paymentAmount * $item->get("{$prefix}_total") / $invoice->get("{$prefix}_total");
         }
     } else {
         // for higher tier just take amount paid to previous tier
         $paidForItem = $paymentAmount;
     }
     foreach ($this->findRules($invoice, $item, $aff, $paymentNumber, $tier, $paymentDate) as $rule) {
         if ($rule->type == AffCommissionRule::TYPE_MULTI) {
             $multi *= $rule->multi;
         } else {
             if ($paidForItem == 0) {
                 // free signup?
                 if ($paymentNumber == 0 && $rule->free_signup_c) {
                     return moneyRound($multi * $rule->free_signup_c);
                 }
             } elseif ($paymentNumber == 0) {
                 // first payment
                 if ($rule->first_payment_t == '%') {
                     return moneyRound($multi * $rule->first_payment_c * $paidForItem / 100);
                 } else {
                     return moneyRound($multi * $rule->first_payment_c);
                 }
             } else {
                 // first payment
                 if ($rule->recurring_t == '%') {
                     return moneyRound($multi * $rule->recurring_c * $paidForItem / 100);
                 } else {
                     return moneyRound($multi * $rule->recurring_c);
                 }
             }
         }
     }
 }
Esempio n. 5
0
    exit;
}
if ($_POST['action'] == 'get_employer_info') {
    $criteria = array('columns' => "employers.id, employers.name, employers.contact_person, employers.email_addr", 'joins' => "employers ON employers.id = invoices.employer", 'match' => "invoices.id = " . $_POST['id'], 'limit' => "1");
    $result = Invoice::find($criteria);
    if ($result === false || is_null($result) || count($result) <= 0) {
        echo '0';
        exit;
    }
    $response = array('employer' => $result);
    header('Content-type: text/xml');
    echo $xml_dom->get_xml_from_array($response);
    exit;
}
if ($_POST['action'] == 'resend') {
    $invoice = Invoice::get($_POST['id']);
    $invoice[0]['items'] = Invoice::getItems($_POST['id']);
    $employer = new Employer($invoice[0]['employer']);
    $recipients = $employer->getEmailAddress();
    if (isset($_POST['recipients'])) {
        if (!empty($_POST['recipients'])) {
            $recipients = str_replace(';', ',', $_POST['recipients']);
        }
    }
    $branch = $employer->getAssociatedBranch();
    $sales = 'sales.' . strtolower($branch[0]['country']) . '@yellowelevator.com';
    $branch[0]['address'] = str_replace(array("\r\n", "\r"), "\n", $branch[0]['address']);
    $branch['address_lines'] = explode("\n", $branch[0]['address']);
    $currency = Currency::getSymbolFromCountryCode($branch[0]['country']);
    $amount_payable = 0.0;
    foreach ($invoice[0]['items'] as $i => $item) {
Esempio n. 6
0
 public function calculate(Invoice $invoice, InvoiceItem $item, User $aff, $paymentNumber = 0, $tier = 0, $paymentAmount = 0.0, $paymentDate = 'now', &$matchedRules = array())
 {
     // take aff.commission_days in account for 1-tier only
     if ($tier == 0 && ($commissionDays = $this->getDi()->config->get('aff.commission_days'))) {
         $signupDays = $this->getDi()->time - strtotime($invoice->getUser()->aff_added ? $invoice->getUser()->aff_added : $invoice->getUser()->added);
         $signupDays = intval($signupDays / (3600 * 24));
         // to days
         if ($commissionDays < $signupDays) {
             return;
         }
         // no commission for this case, affiliate<->user relation is expired
     }
     $multi = 1.0;
     $isFirst = $paymentNumber <= 1;
     $prefix = $isFirst && (double) $item->first_total ? 'first' : 'second';
     if ($tier == 0) {
         if ($invoice->get("{$prefix}_total") == 0) {
             $paidForItem = 0;
         } else {
             $paidForItem = $paymentAmount * $item->get("{$prefix}_total") / $invoice->get("{$prefix}_total");
         }
     } else {
         // for higher tier just take amount paid to previous tier
         $paidForItem = $paymentAmount;
     }
     $paidForItem = $tier ? $paidForItem : $paidForItem / $invoice->base_currency_multi;
     foreach ($this->findRules($invoice, $item, $aff, $paymentNumber, $tier, $paymentDate) as $rule) {
         array_push($matchedRules, $rule);
         // Second tier commission have to be calculated as percent from First tier commission.
         if ($tier > 0) {
             return moneyRound($rule->first_payment_c * $paidForItem / 100);
         }
         if ($rule->type == AffCommissionRule::TYPE_MULTI) {
             $multi *= $rule->multi;
         } else {
             if ($paidForItem == 0) {
                 // free signup?
                 if ($paymentNumber == 0 && $rule->free_signup_c) {
                     return moneyRound($multi * $rule->free_signup_c);
                 }
             } elseif ($isFirst) {
                 // first payment
                 if ($rule->first_payment_t == '%') {
                     return moneyRound($multi * $rule->first_payment_c * $paidForItem / 100);
                 } else {
                     return moneyRound($multi * $rule->first_payment_c);
                 }
             } else {
                 // recurring payment
                 if ($rule->recurring_t == '%') {
                     return moneyRound($multi * $rule->recurring_c * $paidForItem / 100);
                 } else {
                     return moneyRound($multi * $rule->recurring_c);
                 }
             }
         }
     }
 }
Esempio n. 7
0
 /**
  * 
  * @param int $invoiceMapId
  * @return \ifirma\SendResult
  */
 private function _sendInvoiceBasedOnProforma($invoiceMapId)
 {
     global $loader, $registry;
     $loader->model('module/invoice_map');
     $invoiceMapModel = $registry->get('model_module_invoice_map');
     $invoiceMap = $invoiceMapModel->get($invoiceMapId);
     if ($invoiceMap === null) {
         return SendResult::makeInvalidResponse(SendResult::MESSAGE_MISSING_INVOICE_PROFORMA);
     }
     $invoiceResponseObj = $this->_getInvoiceResponseObject($invoiceMap);
     if ($invoiceResponseObj === null) {
         return SendResult::makeInvalidResponse(SendResult::MESSAGE_MISSING_INVOICE_PROFORMA);
     }
     $sendInvoiceResult = $invoiceResponseObj->sendInvoiceBasedOnThisProforma();
     if (!$sendInvoiceResult->isOk()) {
         return SendResult::makeInvalidResponse($sendInvoiceResult->getMessage() !== '' ? $sendInvoiceResult->getMessage() : SendResult::MESSAGE_UNABLE_TO_SEND_INVOICE);
     }
     $sendInvoiceResultContent = $sendInvoiceResult->getContent();
     $newInvoiceId = $sendInvoiceResultContent[ConnectorResponse::KEY_INVOICE_ID];
     $newInvoiceObj = Invoice::get($newInvoiceId);
     $this->_createAndSaveInvoiceMapObject($newInvoiceId, $invoiceMap[ModelModuleInvoiceMap::COLUMN_NAME_ORDER_ID], ModelModuleInvoiceMap::INVOICE_TYPE_NORMAL, Invoice::filterNumber($newInvoiceObj->{InvoiceResponse::KEY_PELNY_NUMER}));
     //                $invoiceMapModel->updateInvoiceNumber($invoiceMap[ModelModuleInvoiceMap::COLUMN_NAME_ORDER_ID], Invoice::filterNumber($newInvoiceObj->{InvoiceResponse::KEY_PELNY_NUMER}));
     return SendResult::makeValidResponse($sendInvoiceResult->getMessage() !== '' ? $sendInvoiceResult->getMessage() : SendResult::MESSAGE_INVOICE_SUCCESSFULLY_SEND);
 }
Esempio n. 8
0
        $root_items = explode('/', $GLOBALS['root']);
        foreach ($root_items as $value) {
            if ($value == 'yel') {
                $is_dev = true;
                break;
            }
        }
        if (!$is_dev) {
            ?>
            <script type="text/javascript">alert('Please logout from your existing connection before proceeding.');</script>
            <?php 
            exit;
        }
    }
}
$invoice = Invoice::get($_GET['id']);
$items = Invoice::getItems($_GET['id']);
if (!$invoice) {
    echo "Invoice not found.";
    exit;
}
$employer = new Employer($invoice[0]['employer']);
$branch = $employer->getAssociatedBranch();
$currency = Currency::getSymbolFromCountryCode($branch[0]['country']);
$amount_payable = 0.0;
foreach ($items as $i => $item) {
    $amount_payable += $item['amount'];
    $items[$i]['amount'] = number_format($item['amount'], 2, '.', ', ');
}
$amount_payable = number_format($amount_payable, 2, '.', ', ');
$invoice_or_receipt = is_null($invoice[0]['paid_on']) || empty($invoice[0]['paid_on']) ? 'Invoice' : 'Receipt';
Esempio n. 9
0
 function get_invoices()
 {
     $invoice = new Invoice();
     $invoices = $invoice->get("WHERE project_id = {$this->id}");
     return $invoices;
 }