[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb:[6282] addons/1.3/wxPOS



Revision: 6282
          http://sourceforge.net/p/ledger-smb/code/6282
Author:   einhverfr
Date:     2013-11-11 11:12:09 +0000 (Mon, 11 Nov 2013)
Log Message:
-----------
Initial work done on AP invoices

Modified Paths:
--------------
    addons/1.3/wxPOS/setup/invoices.sql

Added Paths:
-----------
    addons/1.3/wxPOS/WXPOS/UI/AP/
    addons/1.3/wxPOS/WXPOS/UI/AP/Pay.pm
    addons/1.3/wxPOS/WXPOS/UI/AP.pm

Removed Paths:
-------------
    addons/1.3/wxPOS/WXPOS/UI/AP/Pay.pm

Deleted: addons/1.3/wxPOS/WXPOS/UI/AP/Pay.pm
===================================================================
--- addons/1.3/wxPOS/WXPOS/UI/AR/Pay.pm	2013-11-08 07:25:27 UTC (rev 6260)
+++ addons/1.3/wxPOS/WXPOS/UI/AP/Pay.pm	2013-11-11 11:12:09 UTC (rev 6282)
@@ -1,49 +0,0 @@
-
-package WXPOS::UI::AR::Pay;
-use Wx qw(wxDefaultPosition wxDefaultSize wxOK wxCENTRE wxTE_PASSWORD wxCLOSE_BOX wxBITMAP_TYPE_PNG);
-use base qw(Wx::Dialog);
-use Wx::Event qw(EVT_BUTTON);
-use WXPOS::Sysconfig;
-
-sub new{
-    my ($class, $parent) = @_;
-    my $self =  Wx::Dialog->new(undef , -1, "LedgerSMB", wxDefaultPosition, 
-        [600, 400]);
-    bless $self, $class;
-    $self->{parent_window} = $parent; # Need this access for storing payments 
-    $self->{WxPanel} = Wx::Panel->new($self, -1, wxDefaultPosition, [800, 300]);
-    Wx::InitAllImageHandlers();
-
-    ### ENTRY LINE:  Amount, Type, Source
-    Wx::StaticText->new($self->{WxPanel}, -1, 'Amount', [50, 00], [80, 24]);
-    $self->{payment} = Wx::TextCtrl->new($self->{WxPanel}, -1, '', 
-                                 [130, 00], [60, 24]
-    );
-    Wx::StaticText->new($self->{WxPanel}, -1, 'Type', [200, 00], [80, 24]);
-    $self->{memo} = Wx::ComboBox->new($self->{WxPanel}, -1, $list->[0], 
-                                 [250, 0], [60, 24], [''], wxCB_READONLY);
-    
-    Wx::StaticText->new($self->{WxPanel}, -1, 'Source', [300, 00], [80, 24]);
-    $self->{source} = Wx::TextCtrl->new($self->{WxPanel}, -1, '', 
-                                 [350, 00], [60, 24]
-    );
-    
-
-    ### LIST BOX
-
-    ### POST/CANCEL BUTTONS
-
-    ### SHOW DIALOG
-    $self->ShowModal();
-}
-
-sub _AddPayment {
-}
-
-sub _Cancel{
-}
-
-sub _Post {
-}
-
-1;

Copied: addons/1.3/wxPOS/WXPOS/UI/AP/Pay.pm (from rev 6279, addons/1.3/wxPOS/WXPOS/UI/AR/Pay.pm)
===================================================================
--- addons/1.3/wxPOS/WXPOS/UI/AP/Pay.pm	                        (rev 0)
+++ addons/1.3/wxPOS/WXPOS/UI/AP/Pay.pm	2013-11-11 11:12:09 UTC (rev 6282)
@@ -0,0 +1,216 @@
+
+package WXPOS::UI::AP::Pay;
+use Wx qw(wxDefaultPosition wxDefaultSize wxOK wxCENTRE wxICON_ERROR wxTE_PASSWORD 
+          wxCLOSE_BOX wxBITMAP_TYPE_PNG wxCB_READONLY wxLC_REPORT
+          wxALIGN_RIGHT :sizer);
+use base qw(Wx::Dialog);
+use Wx::Event qw(EVT_BUTTON EVT_LIST_ITEM_SELECTED EVT_LIST_ITEM_DESELECTED);
+use WXPOS::Sysconfig;
+use WXPOS::Invoice;
+use Try::Tiny;
+use Carp;
+use strict;
+use warnings;
+
+sub new{
+    my ($class, $parent) = @_;
+    my $self =  Wx::Dialog->new(undef , -1, "LedgerSMB", wxDefaultPosition, 
+        [600, 400]);
+    bless $self, $class;
+    $self->{parent_window} = $parent; # Need this access for storing payments 
+    $self->{WxPanel} = Wx::Panel->new($self, -1, wxDefaultPosition, [600, 400]);
+    Wx::InitAllImageHandlers();
+
+    ### ENTRY LINE:  Amount, Type, Source
+    Wx::StaticText->new($self->{WxPanel}, -1, 'Amount', [50, 00], [80, 24]);
+    $self->{payment} = Wx::TextCtrl->new($self->{WxPanel}, -1, '', 
+                                 [130, 00], [60, 24]
+    );
+    Wx::StaticText->new($self->{WxPanel}, -1, 'Type', [200, 00], [80, 24]);
+    my $paytypes = $WXPOS::Sysconfig::payment_types;
+    $paytypes = [''] unless @$paytypes;
+    $self->{memo} = Wx::ComboBox->new($self->{WxPanel}, -1, $paytypes->[0], 
+                                 [250, 0], [80, 24], 
+                                 $paytypes, wxCB_READONLY);
+    
+    Wx::StaticText->new($self->{WxPanel}, -1, 'Source', [360, 00], [80, 24]);
+    $self->{source} = Wx::TextCtrl->new($self->{WxPanel}, -1, '', 
+                                 [405, 00], [60, 24]
+    );
+
+    my $add_pmt_btn = Wx::Button->new($self->{WxPanel}, -1, 'Add', 
+                                 [460, 0], [60, 24]);
+    EVT_BUTTON($self->{WxPanel}, $add_pmt_btn, sub{$self->_AddPayment});
+
+    ### LIST BOX
+    $self->{list} = Wx::ListCtrl->new($self->{WxPanel}, -1, 
+                                 [10, 30], [580, 200], wxLC_REPORT);
+    $self->{list}->InsertColumn(1, 'Amount');
+    $self->{list}->InsertColumn(2, 'Type');
+    $self->{list}->InsertColumn(3, 'Source');
+    EVT_LIST_ITEM_SELECTED($self->{WxPanel}, $self->{list}, sub{$self->_selPay});
+    EVT_LIST_ITEM_DESELECTED($self->{WxPanel}, $self->{list}, sub{$self->_selPay});
+
+    ### SELECTION/REMOVAL LINE
+
+    Wx::StaticText->new($self->{WxPanel}, -1, 'Selected: ', 
+                                 [10, 240], [90, 24]);
+    $self->{delete_pay} = Wx::StaticText->new($self->{tab}, -1, '', 
+                                 [100, 240], [30, 24]);
+    my $del_pay = Wx::Button->new($self->{WxPanel}, -1, 'Del', 
+                                 [140, 240], [60, 24]);
+    EVT_BUTTON($self->{WxPanel}, $del_pay, sub{$self->_delPay});
+
+    ### TOTAL/POST/CANCEL BUTTONS
+    Wx::StaticText->new($self->{WxPanel}, -1, 'Total: ',
+                                 [10, 280], [90, 24]
+    );
+    $self->{total} = Wx::StaticText->new($self->{WxPanel}, -1, 
+                                 $self->{parent_window}->{total}->GetLabel,
+                                 [100, 280], [90, 24]
+    );
+    Wx::StaticText->new($self->{WxPanel}, -1, 'Total Paid: ',
+                                 [10, 300], [90, 24]
+    );
+
+    $self->{total_paid} = Wx::StaticText->new($self->{WxPanel}, -1, '',
+                                 [100, 300], [90, 24]);
+    $self->{oweing_label} = Wx::StaticText->new($self->{WxPanel}, -1, 'Oweing: ',
+                                 [10, 320], [90, 24]);
+    $self->{oweing} =  Wx::StaticText->new($self->{WxPanel}, -1, '',
+                                 [100, 320], [90, 24]);
+
+    my $post_btn =  Wx::Button->new($self->{WxPanel}, -1, 'Post',
+                                 [10, 360], [60, 24]);
+    my $cancel_btn =  Wx::Button->new($self->{WxPanel}, -1, 'Cancel',
+                                 [500, 360], [60, 24]);
+    EVT_BUTTON($self->{WxPanel}, $post_btn, sub{$self->_Post});
+    EVT_BUTTON($self->{WxPanel}, $cancel_btn, sub{$self->_Cancel});
+    $self->{paylist} = [];
+
+    ### SHOW DIALOG
+    $self->ShowModal();
+}
+
+sub _selPay {
+}
+
+sub _delPay {
+}
+
+sub _AddPayment {
+   my ($self) = @_;
+   #Variables
+   my $num = $self->{list}->GetItemCount();
+   my $amount = $self->{payment}->GetValue();
+   my $type = $self->{memo}->GetValue();
+   my $source= $self->{source}->GetValue();
+   my $paid = $self->{total_paid}->GetLabel();
+   my $owing = $self->{oweing}->GetLabel();
+   my $total = $self->{total}->GetLabel();
+
+   # Update labels
+   $paid ||= 0;
+   $paid += $amount;
+   $self->{total_paid}->SetLabel($paid);
+   $owing = $self->{parent_window}->format_money($total - $paid);
+   if ($owing < 0) {
+       $self->{oweing_label}->SetLabel('Change');
+       $self->{oweing}->SetLabel($owing * -1);
+   } else {
+       $self->{oweing_label}->SetLabel('Oweing');
+       $self->{oweing}->SetLabel($owing);
+   }
+
+   # update list;
+   my $item = $self->{list}->InsertStringItem($num, $amount);
+   $self->{list}->SetItem($item, 1, $type);
+   $self->{list}->SetItem($item, 2, $source);
+}
+
+sub _Cancel{
+    my ($self) = @_;
+    $self->EndModal(0);
+}
+
+sub _Post {
+    my ($self) = @_;
+    my $invoice = WXPOS::Invoice->from_UI($self, 1);
+    try {
+      $invoice->post;
+    } catch {
+      Wx::MessageBox("Something went wrong.  Please try again",
+                   "More information has been logged on this error",
+                    wxOK|wxCENTRE|wxICON_ERROR, $self->{tab});
+      warn $_;
+      return undef;
+    }
+    $invoice->print(); # TODO
+    # Ok, we succeeded, now to close the current tab and window, 
+    # and initialize the next one.  -CT
+    $self->{parent_window}->_close_pane;
+    $self->EndModal(0);
+}
+
+sub get_entity_credit_account {
+    my ($self) = @_;
+    return $self->{parent_window}->{customer_search}
+           ->{$self->{parent_window}->{customer_list}->GetValue()};;
+}
+
+sub get_amounts {
+    my ($self) = @_;
+    my $amounts = {};
+    $amounts->{paid} = $self->{total_paid}->GetLabel();
+    $amounts->{netamount} = $self->{parent_window}->{net_total}->GetLabel();
+    $amounts->{amount} = $self->{total}->GetLabel();
+    return $amounts;
+}
+
+sub get_lines {
+    my ($self) = @_;
+    my $lines = [];
+    my $list = $self->{parent_window}->{list};
+    my $item = -1;
+
+    while (($item = $list->GetNextItem($item)) > -1){
+        my $line = {};
+        $line->{partnumber} = $list->GetItem($item, 0)->GetText(); 
+        $line->{sellprice} = $list->GetItem($item, 2)->GetText();
+        $line->{qty} =  $list->GetItem($item, 6)->GetText();
+        push @$lines, $line;
+    }
+    
+    return $lines; 
+}
+
+sub get_payments {
+    my ($self) = @_;
+    my $list = $self->{list};
+    my $item = -1;
+    my $payments = [];
+    while (($item = $list->GetNextItem($item)) > -1){
+       my $pmt = {};
+       $pmt->{amount} = $list->GetItem($item, 0)->GetText();
+       $pmt->{memo} = $list->GetItem($item, 1)->GetText();
+       $pmt->{source} = $list->GetItem($item, 2)->GetText();
+       push @$payments, $pmt;
+    }
+
+    # Change
+    my $amounts = $self->get_amounts();
+    if (!$amounts->{paid} and $amounts->{total}){
+       return undef;
+    }
+    $amounts->{paid} ||=0;
+    if ($amounts->{amount} < $amounts->{paid}){
+        push @$payments, {
+           amount => $amounts->{amount} - $amounts->{paid},
+           memo => 'cash',
+           source => 'change'
+        };
+    }   
+    return $payments;
+}
+
+1;

Copied: addons/1.3/wxPOS/WXPOS/UI/AP.pm (from rev 6277, addons/1.3/wxPOS/WXPOS/UI/AR.pm)
===================================================================
--- addons/1.3/wxPOS/WXPOS/UI/AP.pm	                        (rev 0)
+++ addons/1.3/wxPOS/WXPOS/UI/AP.pm	2013-11-11 11:12:09 UTC (rev 6282)
@@ -0,0 +1,273 @@
+package WXPOS::UI::AR;
+
+use Wx qw(wxDefaultPosition wxDefaultSize wxLI_HORIZONTAL wxCB_READONLY wxICON_ERROR wxOK wxCENTRE wxLC_REPORT wxLIST_NEXT_ALL wxLIST_STATE_SELECTED wxLIST_STATE_DONTCARE wxLIST_NEXT_BELOW wxLC_VIRTUAL);
+use Wx::Event qw(EVT_BUTTON EVT_LISTBOX_DCLICK EVT_COMBOBOX EVT_LIST_ITEM_RIGHT_CLICK EVT_LIST_ITEM_SELECTED EVT_LIST_ITEM_DESELECTED);
+use base qw(Wx::Frame);
+use Wx::Grid;
+use WXPOS::Part;
+use WXPOS::Counterparty;
+use lib 'scripts';
+use WXPOS::UI::AR::Pay;
+use Math::BigFloat; # for rounding
+
+# TODO:
+# Need payment/posting screen
+# No hardware support/printing support yet.
+# Dropping warehouse search restrictions currently.
+
+sub new {
+ my ($class, $sesion, $action) = @_;
+ my $self = {};
+ $self->{sesion} = $sesion;
+ bless $self, $class;
+ return $self->$action();
+}
+
+####### Invoice Screen
+sub Invoice {
+ my ($self) = @_;
+ $self->{sesion}->{tk} = undef;
+ $self->{sesion}->{tk}->{items} = 0;
+ $self->{tab} = Wx::Panel->new($self->{sesion}->{nb}, -1, wxDefaultPosition, wxDefaultSize);
+
+### Close Window Button
+ my $close_btn = Wx::Button->new($self->{tab}, -1, '[X]', [750, 3], [30, 24]);
+ EVT_BUTTON($self->{tab}, $close_btn, sub{$self->_close_pane});
+
+### Vendor
+ my $dft_vendor = $self->{sesion}->{defaults}->{vendor} || '';
+ $dft_vendor ||= $WXPOS::Sysconfig::default_vendor;
+ Wx::StaticLine->new($self->{tab}, -1, [0, 0], [800, 2], wxLI_HORIZONTAL);
+ Wx::StaticText->new($self->{tab}, -1, 'Vendor', [10, 10], [90, 24]);
+ $self->{vendor} = Wx::TextCtrl->new($self->{tab}, -1, $dft_vendor , [110, 10], [90, 24]);
+ my $vend_but = Wx::Button->new($self->{tab}, -1, 'Search', [210, 10], [90, 24]);
+ EVT_BUTTON($self->{tab}, $vend_but, sub{$self->_listVendorByName});
+ $self->{vendor_list} = Wx::ComboBox->new($self->{tab}, -1, '', [10, 40], [290, 24], [''], wxCB_READONLY);
+ Wx::StaticLine->new($self->{tab}, -1, [0, 70], [800, 2], wxLI_HORIZONTAL);
+### Parts Search
+
+ my $warehouse = $self->{sesion}->{defaults}->{wh} || '';
+ Wx::StaticText->new($self->{tab}, -1, 'Warehouse: '.$warehouse, [10,120], [120, 24]);
+ Wx::StaticText->new($self->{tab}, -1, 'Description', [140, 120], [90, 24]);
+ $self->{desc} = Wx::TextCtrl->new($self->{tab}, -1, '', [240, 120], [180, 24]);
+ my $parts_but = Wx::Button->new($self->{tab}, -1, 'Search', [440, 120], [60, 24]);
+ EVT_BUTTON($self->{tab}, $parts_but, sub{$self->_listPartsByName});
+ Wx::StaticLine->new($self->{tab}, -1, [0, 150], [800, 2], wxLI_HORIZONTAL);
+
+### Line Entry
+ Wx::StaticText->new($self->{tab}, -1, 'Qty: ', [10, 160], [30, 24]);
+ $self->{part_qty} = Wx::TextCtrl->new($self->{tab}, -1, '1', [50, 160], [30, 24]);
+ Wx::StaticText->new($self->{tab}, -1, 'Number: ', [90, 160], [60, 24]);
+ $self->{part_numb} = Wx::TextCtrl->new($self->{tab}, -1, '', [160, 160], [90, 24]);
+ Wx::StaticText->new($self->{tab}, -1, 'Price: ', [260, 160], [60, 24]);
+ $self->{part_sellprice} 
+     = Wx::TextCtrl->new($self->{tab}, -1, '', [300, 160], [90, 24]);
+ Wx::StaticText->new($self->{tab}, -1, 'Disc: ', [400, 160], [60, 24]);
+ $self->{part_discount} 
+     = Wx::TextCtrl->new($self->{tab}, -1, '', [440, 160], [40, 24]);
+ my $parts_add = Wx::Button->new($self->{tab}, -1, 'Add', [500, 160], [60, 24]);
+ EVT_BUTTON($self->{tab}, $parts_add, sub{$self->_addParts});
+ Wx::StaticText->new($self->{tab}, -1, 'Selected: ', [600, 160], [90, 24]);
+ $self->{sel_del} = Wx::StaticText->new($self->{tab}, -1, '', [690, 160], [30, 24]);
+ my $parts_del = Wx::Button->new($self->{tab}, -1, 'Del', [730, 160], [60, 24]);
+ EVT_BUTTON($self->{tab}, $parts_del, sub{$self->_delParts});
+
+### Ticket
+ $self->{list} = Wx::ListCtrl->new($self->{tab}, -1, [10, 200], [780, 280], wxLC_REPORT);
+ $self->{list}->InsertColumn(1, 'Number');
+ $self->{list}->InsertColumn(2, 'Description');
+ $self->{list}->InsertColumn(3, 'Price');
+ $self->{list}->InsertColumn(4, 'Tax');
+ $self->{list}->InsertColumn(5, 'Ratio');
+ $self->{list}->InsertColumn(6, 'SubTotal');
+ $self->{list}->InsertColumn(7, 'Qty');
+ $self->{list}->InsertColumn(8, 'Total');
+ EVT_LIST_ITEM_SELECTED($self->{tab}, $self->{list}, sub{$self->_selParts});
+ EVT_LIST_ITEM_DESELECTED($self->{tab}, $self->{list}, sub{$self->_selParts});
+
+### Pay
+ Wx::StaticLine->new($self->{tab}, -1, [0, 490], [800, 2], wxLI_HORIZONTAL);
+ Wx::StaticText->new($self->{tab}, -1, 'Net: ', [100, 500], [90, 24]);
+ $self->{net_total} = Wx::StaticText->new($self->{tab}, -1, '', [200, 500], [90, 24]);
+ Wx::StaticText->new($self->{tab}, -1, 'Tax: ', [300, 500], [90, 24]);
+ $self->{tax_total} = Wx::StaticText->new($self->{tab}, -1, '', [400, 500], [90, 24]);
+ Wx::StaticText->new($self->{tab}, -1, 'Total: ', [500, 500], [90, 24]);
+ $self->{total} = Wx::StaticText->new($self->{tab}, -1, '', [600, 500], [90, 24]);
+ my $invoice_post = Wx::Button->new($self->{tab}, -1, 'Pay', [700, 500], [90, 24]);
+ EVT_BUTTON($self->{tab}, $invoice_post, sub{$self->_InvoicePay});
+
+## Finishing
+ if ($dft_vendor){
+    $self->_listVendorByName;
+ }
+ return $self->{tab};
+}
+#######
+
+sub _listVendorByName {
+ my($self, $event) = @_;
+ my $vendor = $self->{vendor}->GetValue();
+ my $list;
+ my $i = 0;
+ foreach (WXPOS::Counterparty->search($vendor , 1)) {
+  push (@{$list}, $_->name);
+  $self->{vendor_search}->{$_->name} = $_->id;
+  $i++;
+ }
+ if ($list) {
+  $self->{vendor_list} = undef;
+  $self->{vendor_list} = Wx::ComboBox->new($self->{tab}, -1, $list->[0], [10, 40], [290, 24], $list);
+ }
+ else {
+  $self->{vendor_list} = undef;
+  $self->{vendor_list} = Wx::ComboBox->new($self->{tab}, -1, '', [10, 40], [290, 24], ['']);
+ }
+ return $self->{vendor_list};
+}
+
+sub _listPartsByName {
+ my ($self, $event) = @_;
+ my $desc = $self->{desc}->GetValue();
+ my $wh = $self->{sesion}->{defaults}->{wh};
+ my $list;
+ my $cust = $self->{vendor_search}->{$self->{vendor_list}->GetValue()};
+ foreach (WXPOS::Part->search($desc, $cust, 2)) {
+  push (@{$list}, $_->description);
+  $self->{parts_search}->{$_->description} = $_->partnumber;
+ }
+ if ($list) {
+  $self->{parts_list} = undef;
+  $self->{parts_list} = Wx::ComboBox->new($self->{tab}, -1, $list->[0], [510, 120], [280, 24], $list, wxCB_READONLY);
+  EVT_COMBOBOX($self->{tab}, $self->{parts_list}, sub{$self->_getPartsNumber});
+ }
+ else {
+  $self->{parts_list} = undef;
+  $self->{parts_list} = Wx::ComboBox->new($self->{tab}, -1, '', [510, 120], [280, 24], [''], wxCB_READONLY);
+ }
+ $self->_getPartsNumber;
+ return $self->{parts_list};
+}
+
+sub _getPartsNumber {
+ my($self, $event) = @_;
+ my $numb = $self->{parts_search}->{$self->{parts_list}->GetValue()};
+ $self->{part_numb}->SetValue($numb);
+ return $self->{part_numb};
+}
+
+
+sub _addParts {
+ my($self, $event) = @_;
+ my $part = $self->{part_numb}->GetValue();
+ my $cust = $self->{vendor_search}->{$self->{vendor_list}->GetValue()};
+### Check for customer
+ if (!$cust) {
+  Wx::MessageBox("Please, try again selecting Vendor.", "Vendor not Found!", wxOK|wxCENTRE|wxICON_ERROR, $self->{tab});
+  return 0;
+ }
+### Check for part
+ if (!$part) {
+  Wx::MessageBox("Please, try again selecting a part.", "Part not Found!", wxOK|wxCENTRE|wxICON_ERROR, $self->{tab});
+  return 0;
+ }
+ $part = WXPOS::Part->get_by_partnumber($part, $cust, 2);
+ my $numb = $part->partnumber;
+ my $desc = $part->description;
+ my $sell = $part->sellprice;
+ if (!$numb) {
+  Wx::MessageBox("Please, try again.", "Part not Found!", wxOK|wxCENTRE|wxICON_ERROR, $self->{tab});
+  return 0;
+ }
+## Price/discount overrides
+ if ($self->{part_sellprice}->GetValue() eq '0' or $self->{part_sellprice}->GetValue()){
+    $sell = $self->{part_sellprice}->GetValue();
+ }
+ my $disc = $self->{part_discount}->GetValue();
+ my $format;
+ if ($disc){
+    $sell = $sell * (100 - $disc)/100;
+    
+ }
+ my $qty = $self->{part_qty}->GetValue();
+ my $total_tax = 0;
+ my $total_tax_ratio = 0;
+### Calculates total ratio and total tax ammount
+ foreach my $tax (@{$self->{sesion}->{ldb}->getTaxByPair($cust, $part)}) {
+  $total_tax_ratio += $tax->[1];
+  $total_tax += $tax->[1] * $sell;
+ }
+ my $st = $total_tax + $sell;
+ my $total = $st * $qty;
+ my $pp = $self->{list}->InsertStringItem($self->{sesion}->{tk}->{items}, $numb);
+ $self->{list}->SetItem($pp, 1, $desc, -1);
+ $self->{list}->SetItem($pp, 2, $self->format_money($sell), -1);
+ $self->{list}->SetItem($pp, 3, $self->format_money($total_tax), -1);
+ $self->{list}->SetItem($pp, 4, $total_tax_ratio, -1);
+ $self->{list}->SetItem($pp, 5, $self->format_money($st), -1);
+ $self->{list}->SetItem($pp, 6, $qty, -1);
+ $self->{list}->SetItem($pp, 7, $self->format_money($total), -1);
+
+ $self->{sesion}->{tk}->{tnet} += $self->format_money($sell);
+ $self->{sesion}->{tk}->{ttax} += $self->format_money($total_tax);
+ $self->{sesion}->{tk}->{total} += $self->format_money($total);
+ $self->{net_total}->SetLabel($self->{sesion}->{tk}->{tnet});
+ $self->{tax_total}->SetLabel($self->{sesion}->{tk}->{ttax});
+ $self->{total}->SetLabel($self->{sesion}->{tk}->{total});
+ $self->{sesion}->{tk}->{items}++;
+ return $part;
+}
+
+sub _selParts {
+ my($self) = @_;
+ $self->{sel_del}->SetLabel($self->{list}->GetSelectedItemCount);
+ return 1;
+}
+
+sub _delParts {
+ my($self) = @_;
+ if ($self->{list}->GetSelectedItemCount < 1) {
+  # Nothing to do, removing dialog since this is time-critical.
+  return 0;
+ }
+ my $item = $self->{list}->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
+ my $sell = $self->{list}->GetItem($item, 2)->GetText();
+ my $total_tax = $self->{list}->GetItem($item, 3)->GetText();
+ my $total = $self->{list}->GetItem($item, 7)->GetText();
+ $self->{sesion}->{tk}->{tnet} -= $sell;
+ $self->{sesion}->{tk}->{ttax} -= $total_tax;
+ $self->{sesion}->{tk}->{total} -= $total;
+ $self->{net_total}->SetLabel($self->{sesion}->{tk}->{tnet});
+ $self->{tax_total}->SetLabel($self->{sesion}->{tk}->{ttax});
+ $self->{total}->SetLabel($self->{sesion}->{tk}->{total});
+ $self->{list}->DeleteItem($item);
+ $self->{sesion}->{tk}->{items}--;
+ $self->{sel_del}->SetLabel($self->{list}->GetSelectedItemCount);
+#use Data::Dumper;
+#print Dumper($item_col);
+ return 1;
+}
+
+sub _close_pane {
+ my ($self) = $_;
+ my $selection = $WXPOS::State::Notebook->GetSelection;
+ $WXPOS::State::Notebook->DeletePage($selection);
+ return 1;
+}
+
+sub _InvoicePay {
+ my($self) = @_;
+ my $total = $self->{total}->GetLabel;
+ $total =~ s/\s//;
+ return undef unless $total ne '' and defined $total; # Can't pay without anything here.
+ WXPOS::UI::AR::Pay->new($self);
+}
+
+sub format_money {
+    my ($self, $string) = @_;
+    $string = $string * 1;
+    $num = Math::BigFloat->new($string);
+    $num->precision($WXPOS::Sysconfig::money_places  * -1);
+    return sprintf("%.0" . ($WXPOS::Sysconfig::money_places) . "f", $num->bstr());
+}
+
+1;

Modified: addons/1.3/wxPOS/setup/invoices.sql
===================================================================
--- addons/1.3/wxPOS/setup/invoices.sql	2013-11-11 10:09:06 UTC (rev 6281)
+++ addons/1.3/wxPOS/setup/invoices.sql	2013-11-11 11:12:09 UTC (rev 6282)
@@ -1,5 +1,34 @@
 BEGIN;
 
+CREATE OR REPLACE FUNCTION invoice__start_ap
+(in_invnumber text, in_transdate date, in_taxincluded bool, 
+ in_amount numeric, in_netamount numeric, in_paid numeric, in_datepaid date,
+ in_duedate date, in_invoice bool, in_curr char(3), person_id int,
+ in_till varchar(20), in_department_id int, in_approved bool, 
+ in_entity_credit_account int, in_ar_accno text)
+RETURNS int LANGUAGE SQL AS
+$$
+ INSERT INTO ap
+        (invnumber, transdate, taxincluded,
+         amount, netamount, paid, datepaid,
+         duedate, invoice, curr, person_id,
+         till, department_id, approved, entity_credit_account)
+ VALUES ($1, $2, coalesce($3, 'f'),
+         $4,$5, $6, coalesce($7, 'today'),
+         coalesce($8, 'today'), $9, coalesce($10,
+         (select defaults_get_defaultcurrency from
+          defaults_get_defaultcurrency())),
+         coalesce($11, person__get_my_entity_id()),
+         $12, $13, coalesce($14, true), $15);
+
+ INSERT INTO acc_trans
+        (trans_id, transdate, chart_id, amount, approved)
+ SELECT currval('id')::int, $2, a.id, $4 * -1true
+   FROM account a WHERE accno = $16;
+
+ SELECT currval('id')::int;
+$$;
+
 CREATE OR REPLACE FUNCTION invoice__start_ar
 (in_invnumber text, in_transdate date, in_taxincluded bool, 
  in_amount numeric, in_netamount numeric, in_paid numeric, in_datepaid date,
@@ -53,13 +82,26 @@
 
 $$;
 
+
+CREATE OR REPLACE FUNCTION invoice__add_item_ap
+(in_id int, in_parts_id int, in_qty numeric, in_discount numeric,
+ in_unit text, in_sellprice numeric)
+RETURNS BOOL LANGUAGE SQL AS
+$$
+INSERT INTO invoice(trans_id, parts_id, qty, discount, unit, allocated, sellprice)
+SELECT $1, p.id, $3 * -1, $4, coalesce($5, p.unit), 0, $6
+  FROM parts p WHERE id = $2;
+
+SELECT TRUE;
+$$;
+
 CREATE OR REPLACE FUNCTION invoice__add_item_ar
 (in_id int, in_parts_id int, in_qty numeric, in_discount numeric,
  in_unit text, in_sellprice numeric)
 RETURNS BOOL LANGUAGE SQL AS
 $$
 INSERT INTO invoice(trans_id, parts_id, qty, discount, unit, allocated, sellprice)
-SELECT $1, p.id, $3, $4, coalesce($5), 0, $6
+SELECT $1, p.id, $3, $4, coalesce($5, p.unit), 0, $6
   FROM parts p WHERE id = $2;
 
 SELECT TRUE;
@@ -87,6 +129,52 @@
 SELECT TRUE;
 $$;
 
+CREATE OR REPLACE FUNCTION invoice__add_payment_ap
+(in_id int, in_ap_accno text, in_cash_accno text, in_transdate date,
+in_source text, in_memo text, in_amount numeric)
+RETURNS BOOL LANGUAGE SQL AS
+$$
+INSERT INTO acc_trans (trans_id, chart_id, transdate, source, memo, amount,
+                       approved)
+VALUES ($1, (select id from account where accno = $2), coalesce($4, 'today'), $5, 
+        $6, $7 * -1, true),
+       ($1, (select id from account where accno = $3), coalesce($4, 'today'), $5, 
+        $6, $7, true);
+
+SELECT TRUE;
+$$;
+
+CREATE OR REPLACE FUNCTION invoice__finalize_ap(in_id int) 
+returns bool language plpgsql as
+$$
+BEGIN
+   -- inventory
+   INSERT INTO acc_trans (trans_id, chart_id, transdate, amount, approved, 
+                         invoice_id)
+   SELECT in_id, p.income_accno_id, a.transdate, i.qty * i.sellprice , true, i.id
+     FROM parts p
+     JOIN invoice i ON i.parts_id = p.id
+     JOIN ar a ON i.trans_id = a.id AND a.id = in_id;
+
+   -- transaction should now be balanced if this was done with invoice__begin_ar
+   -- add cogs
+   PERFORM cogs__add_for_ap(parts_id, qty)
+      FROM invoice WHERE trans_id = in_id;
+
+   -- check if transaction is balanced, else raise exception
+   PERFORM trans_id FROM acc_trans
+     WHERE trans_id = in_id
+  GROUP BY trans_id
+    HAVING sum(amount) <> 0;
+
+   IF FOUND THEN
+      RAISE EXCEPTION 'Out of balance';
+   END IF;
+    
+   RETURN TRUE;
+END;
+$$;
+
 CREATE OR REPLACE FUNCTION invoice__finalize_ar(in_id int) 
 returns bool language plpgsql as
 $$

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.


------------------------------------------------------------------------------
November Webinars for C, C++, Fortran Developers
Accelerate application performance with scalable programming models. Explore
techniques for threading, error checking, porting, and tuning. Get the most 
from the latest Intel processors and coprocessors. See abstracts and register
http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk
_______________________________________________
Ledger-smb-commits mailing list
..hidden..
https://lists.sourceforge.net/lists/listinfo/ledger-smb-commits