Example #1
0
    def generate(self):

        saleId = self.IntReq('Id')
        try:
            sale = Sale.get(Sale.id == saleId)
        except:
            sale = Sale.get()

        self.headers.append(('Id', str(sale.id)))
        self.headers.append(('CustomerId', str(sale.customer.id)))
        self.headers.append(('CustomerName', sale.customer.name))
        self.headers.append(('Date', sale.date))
        self.headers.append(('Time', sale.time))
        self.headers.append(('DateTime', getDate() + ' ' + getTime()))
        self.headers.append(('Remain', '0'))
        self.headers.append(('UserName', sale.user.fullname()))

        details = [d for d in sale.details]
        pages = split(details, _max_rows_)

        for page_details in pages:
            self.Echo('<Page>')
            for row in page_details:
                self.Echo('<Row>')
                self.EchoTag('ProductId', row.id)
                self.EchoTag('StorageName', row.storage.name)
                self.EchoTag('ProductName', row.product.name)
                self.EchoTag('Quantity', row.quantity)
                self.EchoTag('UnitPrice', row.saleprice)
                self.EchoTag('FullPrice', str(row.full_sale()))
                self.Echo('</Row>')
            self.Echo('</Page>')
Example #2
0
    def generate(self):
        orderId = self.IntReq('Id')

        try:
            order = Order.get(Order.id == orderId)
        except:
            order = Order.get()

        self.headers.append(('Id', str(order.id)))
        self.headers.append(('SupplierId', str(order.supplier.id)))
        self.headers.append(('SupplierName', order.supplier.name))
        self.headers.append(('Date', order.date))
        self.headers.append(('Time', order.time))
        self.headers.append(('DateTime', getDate() + ' ' + getTime()))
        self.headers.append(('Storage', order.storage.name))
        self.headers.append(('UserName', order.user.fullname()))

        self.Echo('<Page>')
        for row in order.details:
            self.Echo('<Row>')
            self.EchoTag('ProductId', row.id)
            self.EchoTag('ProductName', row.name)
            self.EchoTag('Category', row.group.name)
            self.EchoTag('Quantity', row.quantity)
            self.EchoTag('UnitPrice', row.purchase)
            self.EchoTag('FullPrice', row.full_purchase())
            self.Echo('</Row>')
        self.Echo('</Page>')
Example #3
0
    def generate(self):

        username = self.StringReq('User')

        try:
            user = User.get(User.username == username)
        except:
            user = User.get()

        self.headers.append(('DateTime', getDate() + ' ' + getTime()))
        self.headers.append(('UserName', user.fullname()))

        list = user.salelist
        list = [d for d in list]

        users = User.select()
        for user in users:
            self.Echo('<User>')
            self.EchoTag('Id', user.username)
            self.EchoTag('UserName', user.fullname())
            self.Echo('</User>')

        pages = split(list, _max_rows_)
        for list in pages:
            self.Echo('<Page>')
            for row in list:
                self.Echo('<Row>')
                self.EchoTag('Id', row.id)
                self.EchoTag('Time', row.time)
                self.EchoTag('Customer', row.customer.name)
                self.EchoTag('FullSale', row.fullsale)
                self.EchoTag('Prepaid', row.advance)
                self.EchoTag('Remain', row.remind())
                self.Echo('</Row>')
            self.Echo('</Page>')
Example #4
0
    def generate(self):
        id = self.IntReq('id')
        pay = SaleInstallment.get(SaleInstallment.id == id)
        self.headers.append(('Serial', str(id)))
        self.headers.append(('Amount', str(pay.amount)))
        self.headers.append(('DateBack', pay.dateback))
        self.headers.append(('Date', pay.date))
        self.headers.append(('Remain', str(pay.sale.remind())))
        self.headers.append(('DateTime', getDate() + ' ' + getTime()))
        self.headers.append(('SaleId', pay.sale.id))
        self.headers.append(('SaleDate', pay.sale.date))
        self.headers.append(('Customer', pay.sale.customer.name))

        self.Echo('<Page />')
Example #5
0
    def Process(self, args):
        if (self.authentication.Authenticated == True):
            menu = Menu.select().where((Menu.parent >> None) | (Menu.parent >> 0))

            now = getDate()
            _ = config.i18n
            user = self.authentication.SessionObject.user
            fullname = "%s %s" % (user.name, user.family)

            args = {'Title': _('Accounting Web Application'), 'Today': now, 'lang': config.lang_name,
                    'UserName': fullname, 'Navigation': menu, '_': _}

            self.RenderFile("container/main.htm", args)
        else:
            self.RenderFile("container/login.htm", {'_': config.i18n, 'time': getTime()})
Example #6
0
    def generate(self):

        self.headers.append(('DateTime', getDate() + ' ' + getTime()))

        list = Cost().select()
        list = [d for d in list]

        pages = split(list, _max_rows_)
        for list in pages:
            self.Echo('<Page>')
            for row in list:
                self.Echo('<Row>')
                self.EchoTag('Title', row.title)
                self.EchoTag('InvoiceId', row.invoiceno)
                self.EchoTag('RegDate', row.regdate)
                self.EchoTag('Amount', row.amount)
                self.Echo('</Row>')
            self.Echo('</Page>')
Example #7
0
    def generate(self):

        storageId = self.IntReq('Id')
        try:
            storage = Storage.get(Storage.id == storageId)
        except:
            storage = Storage.get()

        self.headers.append(('StorageName', storage.name))
        self.headers.append(('DateTime', getDate() + ' ' + getTime()))

        storages = Storage.select()
        for st in storages:
            self.Echo('<Storage>');
            self.EchoTag('Id', st.id)
            self.EchoTag('Name', st.name)
            self.Echo('</Storage>');

        list = storage.goodlist()
        list = [d for d in list]

        pages = split(list, _max_rows_)
        for list in pages:
            self.Echo('<Page>')
            for row in list:
                self.Echo('<Row>')
                self.EchoTag('ProductId', row.product.id)
                self.EchoTag('StorageName', row.storage.name)
                self.EchoTag('ProductName', row.product.name)
                self.EchoTag('CategoryName', row.product.group.name)
                self.EchoTag('Entrance', row.storage_entrance(storage))
                self.EchoTag('Egress', row.storage_egress(storage))
                self.EchoTag('Current', row.storage_current(storage))

                # self.EchoTag('UnitPrice',row.saleprice)
                # self.EchoTag('FullPrice',str(row.full_sale()))
                self.Echo('</Row>')
            self.Echo('</Page>')
Example #8
0
if __name__ == '__main__':

    # glrobal _
    _ = config.i18n

    PORT = int(os.getenv('PORT', '8000'))
    HOST = os.getenv('HOST', 'localhost')
    httpd = HTTPServer((HOST, PORT), RequestHandler)

    loadControllers()

    # config.makeTempLang(Menu.select())
    # DbSetup().SetupDataBase()
    # DbSetup().BackUp()

    IS_TEST = os.getenv('BUILD_TEST')

    if IS_TEST != 'TEST':
        try:
            print(_('Samal web application server'))
            print(_('Starting server at') + ' http://%s:%s' % (HOST, PORT))
            print('>  %s - %s' % (getDate(), getTime()))
            httpd.serve_forever()
            httpd.server_close()
            print(_('End server listening'))
        except KeyboardInterrupt:
            print(_('Server is Stopped'))
            print('>  %s - %s' % (getDate(), getTime()))
        pass
Example #9
0
    def Process(self, section):

        if section == 'new':
            order = Order()
            storages = Storage.select()
            suppliers = Supplier.select()
            groups = Group.select()
            order.id = 0
            self.RenderFile(
                'purchase/order.htm', {
                    '_': config.i18n,
                    'order': order,
                    'storages': storages,
                    'suppliers': suppliers,
                    'group-list': groups
                })
        elif section == 'edit':
            order = Order.get(Order.id == self.IntReq('id'))

            storages = Storage.select()
            suppliers = Supplier.select()
            groups = Group.select()
            products = order.details

            for sup in suppliers:
                if sup == order.supplier:
                    sup.selected = True

            for stg in storages:
                if stg == order.storage:
                    stg.selected = True

            self.RenderFile(
                'purchase/order.htm', {
                    '_': config.i18n,
                    'order': order,
                    'storages': storages,
                    'suppliers': suppliers,
                    'group-list': groups,
                    'products': products
                })
        elif section == 'save':
            id = self.IntReq('id')
            storageId = self.IntReq('storageId')
            supplierId = self.IntReq('supplierId')

            try:
                order = Order.get(Order.id == id)
            except:
                order = Order()
                order.date = getDate()
                order.time = getTime()
                order.verified = False

            supplier = Supplier.get(Supplier.id == supplierId)
            storage = Storage.get(Storage.id == storageId)

            order.supplier = supplier
            order.storage = storage
            order.user = self.authentication.SessionObject.user
            order.save()

            form = self.getForm()
            row_ids = []
            for key in form.keys():
                if key[0] == 'g':
                    id = self.ToInt(key[(key.find('[') + 1):key.find(']')])
                    row_ids.append(id)
            row_ids.sort()
            keep_rows = []

            pids = []
            # order.clearDetails()

            for row_id in row_ids:
                x = str(row_id)
                group_id = self.IntReq('g[' + x + ']')
                product_id = self.IntReq('i[' + x + ']')

                group = Group.get(Group.id == group_id)
                p = Product()

                if product_id > 0:
                    p = Product.get(Product.id == product_id)

                p.order = order
                p.group = group
                p.name = self.StringReq('n[' + x + ']')
                p.purchase = self.FloatReq('p[' + x + ']')
                p.sale = self.FloatReq('s[' + x + ']')
                p.quantity = self.FloatReq('q[' + x + ']')
                p.save()
                pids.append(p.id)
            order.clearDetails(pids)
            self.RenderJSON({'Id': order.id})
        elif section == 'manage':
            orders = Order.select()
            self.RenderFile('purchase/manage.htm', {
                '_': config.i18n,
                'purchases': orders
            })
Example #10
0
    def Process(self, section):
        if section == 'purchase':
            purchases = Order.select().where(Order.verified == 0)
            self.RenderFile('confirm/purchase.htm', {'_': config.i18n, 'purchases': purchases})

        elif section == 'purchase.details':
            id = self.IntReq('id')
            products = Product.select().where(Product.order == Order.get(Order.id == id))
            self.RenderFile('confirm/purchase.details.htm', {'_': config.i18n, 'products': products})

        elif section == 'purchse.confirm':
            id = self.IntReq('id')
            try:
                o = Order().get(Order.id == id)
                o.verified = 1
                o.save()

                # update storage info
                products = Product.select().join(Order).where(Order.id == o.id)
                for product in products:
                    try:
                        sc = StorageChange.get(
                            (StorageChange.product == product) & (StorageChange.storage == o.storage))
                        sc.enter += product.quantity
                    except:
                        sc = StorageChange()
                        sc.storage = o.storage
                        sc.product = product
                        sc.date = getDate()
                        sc.time = getTime()
                        sc.enter = product.quantity
                        sc.purchase = product.purchase
                        sc.sell = product.sale
                        sc.reftype = 1
                        sc.refid = o.id

                    sc.save()

                self.RenderJSON({'result': 'OK'})
            except:
                self.RenderJSON({'result': 'NO'})

        elif section == 'sale':
            sales = Sale.select().where(Sale.verified == 0)
            self.RenderFile('confirm/sale.htm', {'_': config.i18n, 'sales': sales})

        elif section == 'sale.details':
            sale = Sale.get(Sale.id == self.IntReq('id'))
            details = sale.details
            i = 1
            for detail in details:
                detail.index = i
                i = i + 1

            customers = Person.select()
            storages = Storage.select()

            for cus in customers:
                if cus == sale.customer:
                    cus.selected = True

            self.RenderFile('confirm/sale.details.htm', {
                '_': config.i18n,
                'Sale': sale,
                'Sale_details': details,
                'Storages': storages,
                'Customers': customers
            })

        elif section == 'sale.confirm':
            id = self.IntReq('id')
            try:
                s = Sale().get(Sale.id == id)
                s.verified = 1
                s.save()

                # update storage info
                # saledetails = SaleDetails.select().join(Sale).where(Sale.id == s.id)
                # for sd in saledetails:
                #     try:
                #         sc = StorageChange.get((StorageChange.product == sd.product) & (StorageChange.storage == sd.storage))
                #         sc.export += sd.quantity
                #         sc.sell = sd.saleprice
                #         sc.purchase = sd.product.purchase
                #         sc.save()
                #     except:
                #         self.RenderJSON({'result':'NO'})

                self.RenderJSON({'result': 'OK'})
            except:
                self.RenderJSON({'result': 'NO'})
Example #11
0
    def Process(self, section):
        if section == 'new':
            customers = Person.select()
            storages = Storage.select()
            sale = Sale()
            sale.id = 0
            sale.advance = 0
            sale.date = getDate()
            self.RenderFile(
                'sale/sale.htm', {
                    '_': config.i18n,
                    'Customers': customers,
                    'Storages': storages,
                    'Sale': sale
                })
        elif section == 'edit':
            sale = Sale.get(Sale.id == self.IntReq('id'))

            details = sale.details
            i = 1
            for detail in details:
                detail.index = i
                i = i + 1
            i = 1

            installments = sale.installments
            for si in installments:
                si.index = i
                i = i + 1

            customers = Person.select()
            storages = Storage.select()

            for cus in customers:
                if cus == sale.customer:
                    cus.selected = True

            self.RenderFile(
                'sale/sale.htm', {
                    '_': config.i18n,
                    'Sale': sale,
                    'Sale_details': details,
                    'Sale_installments': installments,
                    'Storages': storages,
                    'Customers': customers
                })
        elif section == 'save':
            id = self.IntReq('id')
            pays = self.IntReq('pays')
            prepaid = self.FloatReq('prepaid')
            customerId = self.IntReq('customerId')

            try:
                sale = Sale.get(Sale.id == id)
            except:
                sale = Sale()
                sale.date = getDate()
                sale.time = getTime()
                sale.user = self.authentication.SessionObject.user
                sale.verified = False
            customer = Person.get(Person.id == customerId)

            sale.customer = customer
            sale.installment = pays
            sale.advance = prepaid
            sale.payment = 0
            sale.fullsale = 0

            sale.save()

            form = self.getForm()
            row_ids = []
            srow_ids = []
            for key in form.keys():
                if key[0] == 'g':
                    id = self.ToInt(key[(key.find('[') + 1):key.find(']')])
                    row_ids.append(id)
                elif key[0] == 'b':
                    id = self.ToInt(key[(key.find('[') + 1):key.find(']')])
                    srow_ids.append(id)

            row_ids.sort()
            srow_ids.sort()

            sale.clearDetails()
            full_sale = 0

            for row_id in row_ids:
                x = str(row_id)
                storage_id = self.IntReq('g[' + x + ']')
                product_id = self.IntReq('p[' + x + ']')
                sale_price = self.FloatReq('s[' + x + ']')
                sale_qty = self.FloatReq('q[' + x + ']')
                full_sale += sale_price * sale_qty

                detail = SaleDetails()
                detail.sale = sale
                detail.product = Product.get(Product.id == product_id)
                detail.quantity = sale_qty
                detail.saleprice = sale_price
                detail.storage = Storage.get(Storage.id == storage_id)
                detail.save()

                schange = StorageChange()
                schange.storage = detail.storage
                schange.product = detail.product
                schange.enter = 0
                schange.export = sale_qty
                schange.purchase = detail.product.purchase
                schange.sell = sale_price
                schange.date = sale.date
                schange.time = sale.time
                schange.reftype = 2
                schange.refid = sale.id
                schange.save()

            for row_id in srow_ids:
                x = str(row_id)
                date = self.StringReq('b_d[' + x + ']')
                pay = self.FloatReq('y_p[' + x + ']')

                sins = SaleInstallment()
                sins.sale = sale
                sins.date = date
                sins.amount = pay
                sins.save()

            sale.fullsale = full_sale
            sale.save()
            self.RenderJSON({'Id': sale.id})

        elif section == 'manage':
            sales = Sale.select()
            self.RenderFile('sale/manage.htm', {
                '_': config.i18n,
                'sales': sales
            })
        elif section == 'return':
            self.output = 'Return'
        elif section == 'installments':
            saleId = self.IntReq('SaleId')
            pqty = self.IntReq('Pays')
            sale = Sale.get(Sale.id == saleId)

            if pqty != sale.installment:
                sale.installment = pqty
                sale.save()
                sale.createInstallments()

            i = 0
            for ins in sale.installments:
                i = i + 1
                ins.index = i
            self.RenderFile('sale/installments.htm', {
                '_': config.i18n,
                'sale': sale
            })