Beispiel #1
0
    def merma_Handle(self, inputs):
        item = int(inputs[Merma.code.name])
        storeDict = {}
        for column in DBProcess(Merma.Merma_tbl).getColumnDefinition:

            if column["name"] in [Merma.created.name] and column["name"] in inputs:
                jdate = general().date2julian(inputs[column["name"]])
                inputs[column["name"]] = jdate

            if column["name"] in inputs:
                storeDict[column["expr"]] = DBProcess(Merma.Merma_tbl).parse(column, inputs[column["name"]])

        self.session.query(Merma).filter_by(code=item).update(storeDict)
        self.session.commit()
        self.session.close()
        self.connORM.dispose()

        creator_profile = login().getProfile(inputs)

        user_rootlst = login().Get({User.usrtype.name: 74})["value"]

        url_merma="http://erpt.sugelico.com/?md=merma&merma="+str(item)
        bodymsg = "<h2>Productos mermados</h2>" \
                  "<p>" + \
                  " Colocado por el usuario: " + creator_profile["value"][0]["name"] \
                  + " Codigo del reverso: <a href='" + url_merma + "'>"+str(item)+"</a></p>"

        for user_root in user_rootlst:
            general().sendMail(user_root[User.username.name], bodymsg)
        return {"status": 200, "value": {Merma.code.name: item}, 'type': 'application/json'}
Beispiel #2
0
    def get606(self, inputs):
        from_date = general().date2julian(str(inputs["from_date"]))

        end_date=general().date2julian()
        if "end_date" in inputs:
            end_date=general().date2julian(str(inputs["end_date"]))

        self.msg=[]
        storeDict = self.session.query(buybills.generated,Supplier.sup_name, buybills.ncf,
                                       buybills.subtotal, buybills.total_tax, buybills.total,
                                       buybills.code, buybills.description,Supplier.rnc).\
            filter(Supplier.code == buybills.supplier).\
            filter(buybills.generated >= int(from_date)).\
            filter(buybills.generated <= int(end_date)).\
            order_by(Supplier.sup_name.asc(), buybills.generated.asc()).\
            group_by(Supplier.sup_name, buybills.generated, buybills.ncf,
                     buybills.subtotal, buybills.total_tax,
                     buybills.total,buybills.code, buybills.description,Supplier.rnc)

        for piece in storeDict:
            self.msg.append({buybills.generated.name:general().julian2date(str(piece[0])),
                             Supplier.sup_name.name:piece[1], buybills.ncf.name:piece[2],
                             buybills.subtotal.name:str(piece[3]), buybills.total_tax.name:str(piece[4]),
                             buybills.total.name: str(piece[5]), buybills.code.name:str(piece[6]),
                             buybills.description.name:str(piece[7]),Supplier.rnc.name:str(piece[8])})

        return {"status": 200, "value": self.msg, 'type': 'application/json'}
Beispiel #3
0
    def addEquivalence(self, inputs):
        equivalence = 1
        if "equivalence" in inputs:
            equivalence = float(inputs["equivalence"])

        self.code = CodeGen().GenCode({"table": "Equivalence", "column": "code"})

        Equivalence(code=self.code, eq_name=inputs["eq_name"],
                    from_eq=int(inputs["from_eq"]), to_eq=int(inputs["to_eq"]),
                    equivalence=equivalence, optype="*",
                    created_by=login().decLoginKey(inputs["key"]),
                    created_date=general().date2julian()).save()

        self.reversecode = CodeGen().GenCode({"table": "Equivalence", "column": "code"})

        Equivalence(code=self.reversecode, eq_name=inputs["eq_name"]+"(Reverso)",
                    to_eq=int(inputs["from_eq"]), from_eq=int(inputs["to_eq"]),
                    equivalence=equivalence, optype="/",
                    created_by=login().decLoginKey(inputs["key"]),
                    created_date=general().date2julian()).save()

        self.session.close()
        self.connORM.dispose()

        return {"status": 200, "value": {"code": self.code, "reversecode":self.reversecode}, 'type': 'application/json'}
Beispiel #4
0
    def getBuyItems(self, inputs):
        from_date = general().date2julian()
        if "from" in inputs:
            if len(inputs["from"]) > 4:
                from_date = general().date2julian(inputs["from"])

        end_date = general().date2julian()
        if "end" in inputs:
            if len(inputs["end"]) > 4:
                end_date = general().date2julian(inputs["end"])

        dataCol=[]
        category_filter=and_(Item.category>0)
        if "category" in inputs:
            if int(inputs["category"])>0:
                category_filter = and_(Item.category == int(inputs["category"]))

        products = self.session.query(Item.code).filter(category_filter).order_by(Item.item_name.asc())
        for piece_prod in products:
            for item in Buyitems.objects(created_date__gte=from_date,
                                         created_date__lte=end_date,
                                         product=piece_prod.code):

                item_info=Items().Get({Item.code.name:piece_prod.code})["value"]

                supplier_info = self.session.query(Supplier.sup_name).\
                        filter(buybills.code == item.bill).\
                        filter(buybills.supplier == Supplier.code).first()

                supplier_name=""
                if supplier_info!=None:
                    supplier_name=supplier_info[0]


                product_name=""
                unit_name = "Unidad"
                if len(item_info)>0:
                    product_name=item_info[0][Item.item_name.name]
                    unit_name = item_info[0]["unit_name"]

                dataCol.append({"bill":item.bill,"product":item.product, Item.item_name.name:product_name,
                                "bought_amount":float(item.amount),
                                "unit":unit_name,"date":general().julian2date(str(item.created_date)),
                                "bought_price": '{0:.2f}'.format(float(item.total)), "status":item.status,
                                "status_name":self.session.query(Status.name).
                               filter(Status.code==item.status).first()[0],
                                "supplier":supplier_name, "":item.to_json()})

        self.session.close()
        self.connORM.dispose()

        return {"status": 200, "value": dataCol, 'type': 'application/json'}
Beispiel #5
0
 def getDiaryEntry(self, inputs):
     from_date = general().date2julian(inputs["from"])
     to_date = general().date2julian(inputs["to"])
     entrylst = account_movement.objects(register_date__gte=from_date,
                                         register_date__lte=to_date)
     self.msg = []
     for piece in entrylst:
         date_entry = general().julian2date(str(piece.register_date))
         if piece.credit != None:
             self.msg.append({
                 "account_name":
                 self.session.query(AccountsTbl.account_name).filter(
                     AccountsTbl.code == piece.credit).first()[0],
                 "debit":
                 0.00,
                 "credit":
                 piece.amount,
                 "date":
                 date_entry,
                 "code":
                 piece.code
             })
             self.msg.append({
                 "account_name":
                 self.session.query(AccountsTbl.account_name).filter(
                     AccountsTbl.code == piece.debit).first()[0],
                 "debit":
                 piece.amount,
                 "credit":
                 0.00,
                 "date":
                 date_entry,
                 "code":
                 piece.code
             })
         else:
             self.msg.append({
                 "account_name":
                 self.session.query(AccountsTbl.account_name).filter(
                     AccountsTbl.code == piece.debit).first()[0],
                 "debit":
                 piece.amount,
                 "credit":
                 0.00,
                 "date":
                 date_entry,
                 "code":
                 piece.code
             })
     self.session.close()
     self.connORM.dispose()
     return {"status": 200, "value": self.msg, 'type': 'application/json'}
Beispiel #6
0
    def Handle(self, inputs):
        """This function, save and stores or modify the
        contact information.
        As parameter receive:
        Name.
        LastName.
        CellPhone.
        Telephone.
        Address.
        Email.
        Status.
        """

        item = int(inputs[Contact.code.name])
        birthdate = general().date2julian("1900-01-01")
        if "birthdate" in inputs:
            if len(inputs["birthdate"]) == 9:
                birthdate = general.date2julian(inputs["birthdate"])
        inputs[Contact.birthdate.name] = birthdate

        storeDict = {}
        for column in DBProcess(Contact.Contact_tbl).getColumnDefinition:
            if column["name"] in inputs:
                storeDict[column["expr"]] = DBProcess(
                    Contact.Contact_tbl).parse(column, inputs[column["name"]])

        self.session.query(Contact).filter_by(code=item).update(storeDict)
        self.msg = {"code": item}
        self.session.commit()
        self.session.close()
        self.connORM.dispose()
        return {"status": 200, "value": self.msg, 'type': 'application/json'}
Beispiel #7
0
    def merma_Get(self, inputs):

        storeDict = self.session.query(Merma).filter_by(code = int(inputs["code"])).first()
        dataCol = []
        if storeDict!=None:
            dataDict ={Merma.merma_made.name:storeDict.merma_made,
                       Merma.code.name:storeDict.code,
                       Merma.description.name:storeDict.description,
                       Merma.created.name:general().julian2date(str(storeDict.created)),
                       Merma.created_by.name:login().getProfile({"usercode":storeDict.created_by})["value"]["name"]}

            productsMerma = MermaProd.objects(merma=storeDict.code)
            products = []
            for prodsInMerma in productsMerma:
                #MermaProd(code=mermaprod_code, product=product, amount=float(inputs["amount"]),
                #          merma=self.code).save()
                products.append({"code":prodsInMerma.mermaprod_code,
                                 "product_name":Items().Get({Item.code.name:prodsInMerma.product})
                                 ["value"][0][Item.item_name.name],
                                 "product":prodsInMerma.product, "amount":prodsInMerma.amount})
            dataDict["products"]=products
            dataCol.append(dataDict)

        self.session.close()
        self.connORM.dispose()

        return {"status": 200, "value": dataCol, 'type': 'application/json'}
Beispiel #8
0
    def transfer(self, inputs):
        account_from = None
        if "account_from" in inputs:
            account_from = int(inputs["account_from"])
        account_to = int(inputs["account_to"])
        notes = ""
        if "notes" in inputs:
            notes = str(inputs["notes"])

        amount = float(inputs["amount"])
        code = CodeGen().GenCode({
            "table": "account_movement",
            "column": "code"
        })

        acc_from_info = self.session.query(getaccounts). \
            filter(getaccounts.code == account_from)
        acc_to_info = self.session.query(getaccounts). \
            filter(getaccounts.code == account_to)

        account_movement(credit=account_from,
                         debit=account_to,
                         credit_name=acc_from_info.account_name,
                         credit_code=int(acc_from_info.position_account),
                         debit_name=acc_to_info.account_name,
                         debit_code=int(acc_to_info.position_account),
                         amount=amount,
                         register_date=general().date2julian(),
                         code=code,
                         notes=notes).save()

        cur_amount = self.session.query(AccountsTbl.current_amount).\
            filter(AccountsTbl.code == account_to)

        if (cur_amount != None):
            new_amount = amount + float(cur_amount.first()[0])
            self.session.query(AccountsTbl).filter(AccountsTbl.code==account_to)\
                .update({AccountsTbl.current_amount.name:new_amount})
            self.session.commit()

        if account_from != None:
            cur_amount = float(self.session.query(AccountsTbl.current_amount). \
                filter(AccountsTbl.code == account_from).first()[0])

            cur_amount -= amount
            self.session.query(AccountsTbl).filter(AccountsTbl.code == account_from) \
                .update({AccountsTbl.current_amount.name: cur_amount})

            self.session.commit()

        self.session.close()
        self.connORM.dispose()
        return {
            "status": 200,
            "value": {
                "code": code
            },
            'type': 'application/json'
        }
Beispiel #9
0
    def getBillsBy(self, inputs):
        _from_date = inputs["from"]
        _to_date = inputs["end"]

        from_date = int(general().date2julian(_from_date.split(" ")[0])) + 1
        to_date = int(general().date2julian(_to_date.split(" ")[0])) + 1
        if from_date == to_date:
            bills= self.session.query(BuyItemsRep).filter_by(or_billdate=from_date)
        else:
            bills = self.session.query(BuyItemsRep).\
                filter(BuyItemsRep.or_billdate >= from_date).\
                filter(BuyItemsRep.or_billdate <= to_date)

        if BuyItemsRep.billsupplier.name in inputs:
            if int(inputs[BuyItemsRep.billsupplier.name])>0:
                bills = bills.filter_by(billsupplier=int(inputs[BuyItemsRep.billsupplier.name]))
            else:
                bills = bills.filter(BuyItemsRep.billsupplier > int(inputs[BuyItemsRep.billsupplier.name]))
        if BuyItemsRep.sup_name.name in inputs:
            bills=bills.filter(BuyItemsRep.sup_name.ilike("%"+inputs[BuyItemsRep.sup_name.name]+"%"))

        if BuyItemsRep.sup_rnc.name in inputs:
            bills=bills.filter(BuyItemsRep.sup_rnc.ilike("%"+inputs[BuyItemsRep.sup_rnc.name]+"%"))



        data = bills.order_by(BuyItemsRep.billdate.asc())
        self.msg = []
        for piece in data:
            del piece.__dict__['_sa_instance_state']
            piece.__dict__[BuyItemsRep.billdate.name]=piece.__dict__[BuyItemsRep.billdate.name].strftime("%Y-%m-%d")
            piece.__dict__[BuyItemsRep.billexpires.name]=piece.__dict__[BuyItemsRep.billexpires.name].strftime("%Y-%m-%d")
            piece.__dict__[BuyItemsRep.billpayalert.name]=piece.__dict__[BuyItemsRep.billpayalert.name].strftime("%Y-%m-%d")

            piece.__dict__[BuyItemsRep.billsubtotal.name] = float(piece.__dict__[BuyItemsRep.billsubtotal.name])
            piece.__dict__[BuyItemsRep.billtotal.name] = float(piece.__dict__[BuyItemsRep.billtotal.name])
            piece.__dict__[BuyItemsRep.billtax.name] = float(piece.__dict__[BuyItemsRep.billtax.name])
            piece.__dict__[BuyItemsRep.billothercosts.name] = float(piece.__dict__[BuyItemsRep.billothercosts.name])
            self.msg.append(piece.__dict__)

        self.session.close()
        self.connORM.dispose()
        return {"status": 200, "value": self.msg, 'type': 'application/json'}
Beispiel #10
0
    def get607(self, inputs):
        from_date = general().date2julian(str(inputs["from_date"]))

        end_date=general().date2julian()
        if "end_date" in inputs:
            end_date=general().date2julian(str(inputs["end_date"]))


        details=self.session.query(SalesRep)
        if from_date == end_date:
            details= details.filter_by(billdate=from_date)
        else:

            details= details.\
                filter(SalesRep.billdate >= from_date).\
                filter(SalesRep.billdate <= end_date)

        msg=[]
        details=details.order_by(SalesRep.billncf.asc())
        for piece in details:
            del piece.__dict__['_sa_instance_state']
            if float(piece.__dict__[SalesRep.billtotal.name])>0:
                piece.__dict__["ncf"]=None if piece.__dict__[SalesRep.billncf.name] == None else \
                    ncfType.objects(code=ncf_codes.objects(
                        code=piece.__dict__[SalesRep.billncf.name]).first().ncf_type).first().header+\
                    ncf_codes.objects(code=piece.__dict__[SalesRep.billncf.name]).first().secuence
                if piece.__dict__[SalesRep.client_id.name] !=None :
                    piece.__dict__["rnc"]= ""
                    client_info=self.session.query(Client).\
                        filter_by(code=piece.__dict__[SalesRep.client_id.name]).first()
                    if client_info!=None:
                        piece.__dict__["rnc"] =client_info.rnc
                        piece.__dict__["client_name"] =client_info.cl_name
                msg.append(piece.__dict__)


        self.msg={"details":msg, "total_ncf":len(msg), "total":cashbox_bills.objects(registred__gte=from_date,
                                            registred__lte=end_date).order_by("paytype+").sum('total')/1.28}
        return {"status": 200, "value": self.msg,
                'type': 'application/json'}
Beispiel #11
0
    def Get(self, inputs):
        #This method gets the data, from the db.
        storeDict =[]
        where =and_()
        if buybills.code.name in inputs:
            storeDict = self.session.query(buybills, Status.name, Supplier.sup_name).\
                filter(and_(Status.code == buybills.status, Supplier.code == buybills.supplier,
                            buybills.code== int(inputs[buybills.code.name])))

        elif buybills.supplier.name in inputs and \
                        buybills.generated.name not in inputs and \
                        buybills.expires.name not in inputs:

            storeDict = self.session.query(buybills, Status.name, Supplier.sup_name).\
                filter(and_(Status.code == buybills.status, Supplier.code==buybills.supplier, buybills.supplier
                            == int(inputs[buybills.supplier.name])))

        elif buybills.supplier.name in inputs and \
                 buybills.generated.name in inputs:
            storeDict = self.session.query(buybills, Status.name, Supplier.sup_name). \
                filter(and_(Status.code == buybills.status, buybills.code
                            == int(inputs[buybills.supplier.name])))
        # The next area is in charge to extract the information,
        # from the store Dict and add it to the dataCol to be returned

        dataCol=[]

        for dataLst in storeDict:

            dicStore = {"status_name":dataLst._asdict()["name"],
                        Supplier.sup_name.name: dataLst._asdict()
                        [Supplier.sup_name.name]}

            for key in DBProcess(buybills.buybills_tbl).getColumnDefinition:
                dataDict = dataLst._asdict()[buybills.__name__].__dict__  # Getting the dictionary of the list.
                colname = key["name"]  # Getting the column name.
                if colname in dataDict:  # Just if the column name is on the dictionary, add it to the dictStore.
                    if colname in [buybills.generated.name, buybills.payalert.name, buybills.expires.name]:
                        if dataDict[colname]!=None:
                            jdate = general().julian2date(str(dataDict[colname]))
                            dataDict[colname] = jdate
                        else:
                            dataDict[colname]=" "
                    dicStore[colname] = DBProcess(buybills.buybills_tbl).parse2publish(dataDict[colname])

            dataCol.append(dicStore)
            # Appending everything to be returned

        self.session.close()
        self.connORM.dispose()
        return {"status": 200, "value": dataCol, 'type': 'application/json'}
Beispiel #12
0
    def addItem2Bill(self, inputs):
        self.code = CodeGen().GenCode({"table": "Buyitems", "column": "code"})
        equivalence = 1
        if "from_eq" in inputs:
            equivalence = int(str(inputs["from_eq"]).split(":")[0])
        unit = 517
        if "to_eq" in inputs:
            unit = int(inputs["to_eq"])

        amount = float(inputs["amount"])
        equivalence_data = Equivalence.objects(from_eq=unit, to_eq=equivalence)

        equivalence_info = equivalence_data.first()
        if equivalence_info!= None:
            if equivalence_info.optype == "*":
                amount = float(equivalence_info.equivalence) * float(inputs["amount"])
            if equivalence_info.optype == "/":
                amount = float(equivalence_info.equivalence) / float(inputs["amount"])


        Buyitems(code=self.code, product=int(inputs["product"]), amount=amount,
                 total=float(inputs["total"]), tax=float(inputs["total_tax"]),
                 bill=int(inputs["bill"]),unit=unit,term="",portion="",notes="",
                 created_by=login().decLoginKey(inputs["key"]),created_date=general().date2julian()).save()

        cur_amount = self.session.query(Item.amount).filter_by(code=int(inputs["product"])).first()[0]

        if cur_amount == None or cur_amount=='None':
            cur_amount = 0.00

        Items().Handle({Item.code.name: inputs["product"], Item.amount.name: float(cur_amount) + amount})

        warehouse_info = self.session.query(WareHouse).filter_by(mainwarehouse=True)
        warehouse_info = self.session.query(WareHouse).filter_by(mainwarehouse=True)
        if warehouse_info != None and "amount" in inputs:
            warehose = warehouse_info[0]
            connection = self.connORM.raw_connection()
            cursor = connection.cursor()

            cursor.callproc('products_movement', [self.code, amount,
                                                  warehose.code, 0])
            cursor.close()


        self.session.close()
        self.connORM.dispose()

        return {"status": 200, "value": {"code":self.code}, 'type': 'application/json'}
Beispiel #13
0
    def Handle(self, inputs):
        # This method will modify an expanse.
        if buybills.code.name in inputs:
            item = int(inputs[buybills.code.name])
        else:
            item = CodeGen().GenCode({"table": buybills.__tablename__, "column": buybills.code.name})
            self.session.add(buybills(code=item, status=11))

        storeDict = {}
        for column in DBProcess(buybills.buybills_tbl).getColumnDefinition:
            if column["name"] in [buybills.generated.name, buybills.payalert.name, buybills.expires.name]:
                jdate = general().date2julian(inputs[column["name"]])
                inputs[column["name"]]=jdate


            if column["name"] in inputs:
                storeDict[column["expr"]] = DBProcess(buybills.buybills_tbl).parse(column, inputs[column["name"]])

        self.session.query(buybills).filter_by(code=item).update(storeDict)
        if "products" in inputs:
            products = json.loads(inputs["products"])
            for piece in products:

                amount = float(piece["amount"])
                warehose = 0 if "warehouse" not in inputs else int(inputs["warehouse"])
                if "amount" in piece:

                    connection = self.connORM.raw_connection()
                    cursor = connection.cursor()
                    data =cursor.callproc('products_movement', [int(piece["product"]), amount,
                                                          warehose, 0])

                    cursor.close()
                    connection.commit()
        self.session.commit()
        self.session.close()
        self.connORM.dispose()

        return {"status": 200, "value": {buybills.code.name: item}, 'type': 'application/json'}
Beispiel #14
0
    def Get(self, inputs):
        dataCol = []
        """The module of find the information of a Contact."""
        dataPack = []
        if Contact.contact_name.name in inputs:
            dataPack = self.session.query(Contact, Status.description).\
                filter(and_(Contact.contact_name.like("%"+inputs[Contact.contact_name.name]+"%"), Contact.status==Status.code))

        elif Contact.code.name in inputs:
            dataPack = self.session.query(Contact, Status.description).\
                filter(and_(Contact.code == int(inputs[Contact.code.name]), Contact.status==Status.code))

        for dataLst in dataPack:
            dicStore = {
                "status_name": dataLst._asdict()[Status.description.name]
            }

            for key in DBProcess(Contact.Contact_tbl).getColumnDefinition:
                dataDict = dataLst._asdict()[
                    Contact.
                    __name__].__dict__  # Getting the dictionary of the list.
                colname = key["name"]  # Getting the column name.
                if colname in dataDict:  # Just if the column name is on the dictionary, add it to the dictStore.
                    value = DBProcess(Contact.Contact_tbl).parse2publish(
                        dataDict[colname])

                    if colname == "birthdate":
                        value = general().julian2date(str(dataDict[colname]))

                    dicStore[colname] = value

            dataCol.append(dicStore)
            # Appending everything to be returned

        self.session.close()
        self.connORM.dispose()

        return {"status": 200, "value": dataCol, 'type': 'application/json'}
Beispiel #15
0
    def modItem2Bill(self, inputs):
        self.code = CodeGen().GenCode({"table": "Buyitems", "column": "code"})

        Buyitems.objects(code=self.code).update(set__item=int(inputs["product"]),
                                                set__total_item=float(inputs["total"]), set__total_tax=float(inputs["tax"]),
                                                set__other_costs=float(inputs["other_costs"]),set__discount=float(inputs["discount"]),
                                                set__unit=int(inputs["unit"]), set__equivalence=float(inputs["equivalence"]),
                                                set__created_by=login().decLoginKey(inputs["key"]), set__created_date=general().date2julian())

        cur_amount = Items().Get({Item.code.name: inputs["product"]})["value"][0][Item.amount.name]
        self.session.close()
        self.connORM.dispose()

        return {"status": 200, "value": {"code": self.code}, 'type': 'application/json'}