From c67d248601031a0245dfe64b609fa6623868014b Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Wed, 27 Jul 2016 14:52:49 +0200 Subject: v0.4.2 moved payment_received to separate table/class payment(s) --- include/home.php | 632 ++++++++++++++++++++++++------------------------ include/offers-edit.php | 7 +- 2 files changed, 325 insertions(+), 314 deletions(-) (limited to 'include') diff --git a/include/home.php b/include/home.php index cb624fe..c9d0cf3 100644 --- a/include/home.php +++ b/include/home.php @@ -2,17 +2,17 @@ /** * BusinessAdmin: administrative software for small companies * Copyright (C) 2015 Camil Staps (ViviSoft) - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -24,317 +24,323 @@ require('./header.php');
- - -
-
-
-

Welcome

-
- -
- -
-
- -
-
-
-
- -
-
-
- -
-
-
- - - -
-
-
- = CURDATE()"))); - ?> -
-
-
-
- -
-
-
- -
-
-
- - - -
-
-
- CURDATE()"))); - ?> -
-
-
-
- -
-
-
- -
-
-
- - - -
-
-
- '1970-01-01'", "`invoice_date`<=CURDATE()", "`payment_received` <= '1970-01-01' OR `payment_received` IS NULL"))); - ?> -
-
-
-
- -
-
-
- -
-
-
- - - -
-
-
- -
-
-
-
- Currently active offers -
- -
- = CURDATE()")); - $list = array(); - foreach ($offers as $offer) { - $start = BusinessAdmin::formatDate($offer->getStartDate(), false); - $end = BusinessAdmin::formatDate($offer->getEndDate(), false); - $since = mktime(0,0,0,date("n"),date("j"),date("Y")) - $offer->getStartDate(); - $total = $offer->getEndDate() - $offer->getStartDate(); - $percentage = ($total == 0) ? 100 : round($since / $total * 100); + - // We want to sort on percentage (DESC) and secondly end date (ASC) so start date (DESC) - $base = str_pad($percentage, 3, '0', STR_PAD_LEFT) . $offer->getStartDate(); - for ($i = 0; isset($list["$base-$i"]); $i++); - $list["$base-$i"] = array( - 'start' => $start, - 'end' => $end, - 'id' => $offer->getId(), - 'contactClientName' => $offer->getContact()->getClient()->getName(), - 'percentage' => $percentage, - 'price_excl' => constants::invoice_valuta . $offer->calculate(offer::SUBTOTAL), - 'price_incl' => constants::invoice_valuta . $offer->calculate(offer::TOTAL) - ); - } - krsort($list, SORT_STRING); - foreach ($list as $item) { - echo "

#{$item['id']} to {$item['contactClientName']} ({$item['start']} - {$item['end']}; {$item['price_excl']} excl. VAT, {$item['price_incl']} incl. VAT){$item['percentage']}% complete

-
-
-
"; - } - if (count($list) == 0) { - echo "There are no currently active offers."; - } - ?> -
- -
- -
-
-
-
- Finished offers -
- -
- - - - - - - - - - CURDATE()")); - foreach ($offers as $offer) { - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - } - if (count($offers) == 0) { - echo ""; - } - ?> - -
#ContactOffer ended
{$offer->getId()}{$offer->getContact()->getClient()->getName()}".BusinessAdmin::formatDate($offer->getEndDate(), false)."
There are no offers that need an invoice.
-
- -
- -
-
-
-
- Currently open invoices -
-
- - - - - - - - - - '1970-01-01'", "`invoice_date`<=CURDATE()", "`payment_received` <= '1970-01-01' OR `payment_received` IS NULL")); - if (count($offers) == 0) { - echo ""; - } else { - foreach ($offers as $offer) { - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - } - } - ?> - -
#ContactInvoice sent
There are no currently open invoices.
{$offer->getId()}{$offer->getContact()->getClient()->getName()}".BusinessAdmin::formatDate($offer->getInvoiceDate(), false)."
-
- -
- -
-
- -
-
-
-
- Timeline -
- -
-
    - $offer->getId(), - 'contact' => $offer->getContact()->getName(), - 'assignments' => '', - 'assignments_header' => '' - ); - foreach ($offer->getAssignments() as $assignment) { - $temp['assignments'] .= "{$assignment->getTitle()}
    (".constants::invoice_valuta."{$assignment->calculate(assignment::SUBTOTAL)} excl. VAT, ".constants::invoice_valuta."{$assignment->calculate(assignment::TOTAL)} incl. VAT)

    {$assignment->getDescription()}

    "; - $temp['assignments_header'] .= "{$assignment->getTitle()}
    (".constants::invoice_valuta."{$assignment->calculate(assignment::SUBTOTAL)} excl. VAT, ".constants::invoice_valuta."{$assignment->calculate(assignment::TOTAL)} incl. VAT)
    "; - } - $list[] = array_merge($temp, array('type' => 'start', 'time' => $offer->getStartDate(), 'description' => 'Offer started')); - $sort_list[] = $offer->getStartDate() . $offer->getId() . 0; - $list[] = array_merge($temp, array('type' => 'end', 'time' => $offer->getEndDate(), 'description' => 'Offer ended')); - $sort_list[] = $offer->getEndDate() . $offer->getId() . 1; - if ($offer->getInvoiceDate() > 0) { - $list[] = array_merge($temp, array('type' => 'invoice', 'time' => $offer->getInvoiceDate(), 'description' => 'Invoice sent')); - $sort_list[] = $offer->getInvoiceDate() . $offer->getId() . 2; - if ($offer->getPaymentReceived() > 0) { - $list[] = array_merge($temp, array('type' => 'payment_received', 'time' => $offer->getPaymentReceived(), 'description' => 'Payment received')); - $sort_list[] = $offer->getPaymentReceived() . $offer->getId() . 3; - } - } - } - array_multisort($sort_list, SORT_DESC, $list); - foreach ($list as $item) { - if ($item['time'] > time()) { - continue; - } - echo ""; - switch ($item['type']) { - case 'start': echo "
    "; break; - case 'end': echo "
    "; break; - case 'invoice': echo "
    "; break; - case 'payment_received': echo "
    "; break; - } - echo "
    "; - echo "

    #{$item['id']} to {$item['contact']}: {$item['description']}

    ".BusinessAdmin::formatDate($item['time'],false,true,true)."

    "; - switch ($item['type']) { - case 'start': echo "
    {$item['assignments']}
    "; break; - default: echo "
    {$item['assignments_header']}
    "; - } - echo "
    "; - echo ""; - } - if (count($list) == 0) { - echo '
  • -
    -
    -

    Welcome to BusinessAdmin!

    -
    When you start adding projects, a timeline will appear here.
    -
    -
  • '; - } - ?> -
-
- -
- -
-
-
- +
+
+
+

Welcome

+
+ +
+ +
+
+ +
+
+
+
+ +
+
+
+ +
+
+
+ + + +
+
+
+ = CURDATE()"))); + ?> +
+
+
+
+ +
+
+
+ +
+
+
+ + + +
+
+
+ CURDATE()"))); + ?> +
+
+
+
+ +
+
+
+ +
+
+
+ + + +
+
+
+ '1970-01-01'", + "`invoice_date`<=CURDATE()", + "NOT EXISTS (SELECT * FROM `".constants::db_prefix."payment` WHERE `offerId`=`".constants::db_prefix."offer`.`id` AND `date` != TIMESTAMP(0))"))); + ?> +
+
+
+
+ +
+
+
+ +
+
+
+ + + +
+
+
+ +
+
+
+
+ Currently active offers +
+ +
+ = CURDATE()")); + $list = array(); + foreach ($offers as $offer) { + $start = BusinessAdmin::formatDate($offer->getStartDate(), false); + $end = BusinessAdmin::formatDate($offer->getEndDate(), false); + $since = mktime(0,0,0,date("n"),date("j"),date("Y")) - $offer->getStartDate(); + $total = $offer->getEndDate() - $offer->getStartDate(); + $percentage = ($total == 0) ? 100 : round($since / $total * 100); + + // We want to sort on percentage (DESC) and secondly end date (ASC) so start date (DESC) + $base = str_pad($percentage, 3, '0', STR_PAD_LEFT) . $offer->getStartDate(); + for ($i = 0; isset($list["$base-$i"]); $i++); + $list["$base-$i"] = array( + 'start' => $start, + 'end' => $end, + 'id' => $offer->getId(), + 'contactClientName' => $offer->getContact()->getClient()->getName(), + 'percentage' => $percentage, + 'price_excl' => constants::invoice_valuta . $offer->calculate(offer::SUBTOTAL), + 'price_incl' => constants::invoice_valuta . $offer->calculate(offer::TOTAL) + ); + } + krsort($list, SORT_STRING); + foreach ($list as $item) { + echo "

#{$item['id']} to {$item['contactClientName']} ({$item['start']} - {$item['end']}; {$item['price_excl']} excl. VAT, {$item['price_incl']} incl. VAT){$item['percentage']}% complete

+
+
+
"; + } + if (count($list) == 0) { + echo "There are no currently active offers."; + } + ?> +
+ +
+ +
+
+
+
+ Finished offers +
+ +
+ + + + + + + + + + CURDATE()")); + foreach ($offers as $offer) { + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + } + if (count($offers) == 0) { + echo ""; + } + ?> + +
#ContactOffer ended
{$offer->getId()}{$offer->getContact()->getClient()->getName()}".BusinessAdmin::formatDate($offer->getEndDate(), false)."
There are no offers that need an invoice.
+
+ +
+ +
+
+
+
+ Currently open invoices +
+
+ + + + + + + + + + '1970-01-01'", + "`invoice_date`<=CURDATE()", + "NOT EXISTS (SELECT * FROM `".constants::db_prefix."payment` WHERE `offerId`=`".constants::db_prefix."offer`.`id` AND `date` != TIMESTAMP(0))")); + if (count($offers) == 0) { + echo ""; + } else { + foreach ($offers as $offer) { + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + } + } + ?> + +
#ContactInvoice sent
There are no currently open invoices.
{$offer->getId()}{$offer->getContact()->getClient()->getName()}".BusinessAdmin::formatDate($offer->getInvoiceDate(), false)."
+
+ +
+ +
+
+ +
+
+
+
+ Timeline +
+ +
+
    + $offer->getId(), + 'contact' => $offer->getContact()->getName(), + 'assignments' => '', + 'assignments_header' => '' + ); + foreach ($offer->getAssignments() as $assignment) { + $temp['assignments'] .= "{$assignment->getTitle()}
    (".constants::invoice_valuta."{$assignment->calculate(assignment::SUBTOTAL)} excl. VAT, ".constants::invoice_valuta."{$assignment->calculate(assignment::TOTAL)} incl. VAT)

    {$assignment->getDescription()}

    "; + $temp['assignments_header'] .= "{$assignment->getTitle()}
    (".constants::invoice_valuta."{$assignment->calculate(assignment::SUBTOTAL)} excl. VAT, ".constants::invoice_valuta."{$assignment->calculate(assignment::TOTAL)} incl. VAT)
    "; + } + $list[] = array_merge($temp, array('type' => 'start', 'time' => $offer->getStartDate(), 'description' => 'Offer started')); + $sort_list[] = $offer->getStartDate() . $offer->getId() . 0; + $list[] = array_merge($temp, array('type' => 'end', 'time' => $offer->getEndDate(), 'description' => 'Offer ended')); + $sort_list[] = $offer->getEndDate() . $offer->getId() . 1; + if ($offer->getInvoiceDate() > 0) { + $list[] = array_merge($temp, array('type' => 'invoice', 'time' => $offer->getInvoiceDate(), 'description' => 'Invoice sent')); + $sort_list[] = $offer->getInvoiceDate() . $offer->getId() . 2; + if ($offer->getPaymentReceived() > 0) { + $list[] = array_merge($temp, array('type' => 'payment_received', 'time' => $offer->getPaymentReceived(), 'description' => 'Payment received')); + $sort_list[] = $offer->getPaymentReceived() . $offer->getId() . 3; + } + } + } + array_multisort($sort_list, SORT_DESC, $list); + foreach ($list as $item) { + if ($item['time'] > time()) { + continue; + } + echo ""; + switch ($item['type']) { + case 'start': echo "
    "; break; + case 'end': echo "
    "; break; + case 'invoice': echo "
    "; break; + case 'payment_received': echo "
    "; break; + } + echo "
    "; + echo "

    #{$item['id']} to {$item['contact']}: {$item['description']}

    ".BusinessAdmin::formatDate($item['time'],false,true,true)."

    "; + switch ($item['type']) { + case 'start': echo "
    {$item['assignments']}
    "; break; + default: echo "
    {$item['assignments_header']}
    "; + } + echo "
    "; + echo ""; + } + if (count($list) == 0) { + echo '
  • +
    +
    +

    Welcome to BusinessAdmin!

    +
    When you start adding projects, a timeline will appear here.
    +
    +
  • '; + } + ?> +
+
+ +
+ +
+
+
+
diff --git a/include/offers-edit.php b/include/offers-edit.php index 95de9b3..5ed95c4 100644 --- a/include/offers-edit.php +++ b/include/offers-edit.php @@ -38,7 +38,12 @@ try { $response->success = $offer->setInvoiceDate(strtotime($_REQUEST['value'])); break; case 'payment_received': - $response->success = $offer->setPaymentReceived(strtotime($_REQUEST['value'])); + $payment = $offer->getPayment(); + if (is_null($payment)) { + $response->success = $offer->createPayment(strtotime($_REQUEST['value'])); + } else { + $response->success = $payment->setDate(strtotime($_REQUEST['value'])); + } break; default: $response->http_response_code(404); -- cgit v1.2.3