Subversion Repositories SmartDukaan

Rev

Rev 21847 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

namespace java in.shop2020.purchase
namespace py shop2020.thriftpy.purchase

include "GenericService.thrift"

struct Supplier {
    1:i64 id,
    2:string name,
    3:string phone,
    4:string fax,
    5:string tin,
    6:string pan,
    7:string headName,
    8:string headDesignation,
    9:string headEmail,
    10:string contactName,
    11:string contactPhone,
    12:string contactFax,
    13:string contactEmail,
    14:string registeredAddress,
    15:string communicationAddress,
    16:i64 stateId,
    17:i64 poValidityLimit,
    18:string gstin,
    19:string tnc
}

struct LineItem {
    1:i64 orderId,
    2:i64 itemId,
    3:string productGroup,
    4:string brand,
    5:string modelNumber,
    6:string modelName,
    7:string color,
    8:string itemNumber,
    9:double quantity,
    10:double unfulfilledQuantity,
    11:i64 createdAt,
    12:double unitPrice,
    13:bool fulfilled,
    14:i64 codCount,
    15:i64 availableQuantity,
    16:i64 reservedQuantity,
    17:double avgSales,
    18:i64 minStockLevel,
    19:i64 numberOfDaysStock,
    20:i64 suggestedQuantity,
    21:i64 numberOfDaysInStock,
    22:i64 rtoOrders,
    23:string lastXdaysSale,
    24:i64 previouslyOrderedQty,
    25:double nlc,
    26:double mrp
    27:double nlcP,
    28:double vatDiff,
    29:double igstRate,
        30:double cgstRate,
        31:double sgstRate,
        32:string hsnCode
    
}

enum POStatus {
    INIT = 0,                   //Just created.
    READY = 1,                  //Posted for fulfillment.
    PARTIALLY_FULFILLED = 2,    //Partially fulfullied. Possible to accept purchases against it.
    PRECLOSED = 3,              //PO was partially fulfilled and the supplier has clarified that he can't supply the remaining items. 
    CLOSED = 4                  //PO was completely fulfilled.
}

enum POType {
    REAL = 1,                   //PO created manually
    VIRTUAL = 2                     //Virtual PO generated automatically for Ours_External Billing
}

enum PurchaseReturnType {
    REAL = 1,                   //Purchase Returns where stock is returned to Vendor
    VIRTUAL = 2                     //Virtual Purchase Return associated with Sale Returns for OursExternal Billing
}

enum PurchaseReturnInventoryType {
        GOOD = 1,
        BAD = 2
}

enum TaxType {
        VAT = 0,
        CST = 1,
        CFORM = 2,
        IGST = 3,
        SGST = 4
}

enum PrReasonType {
        WRONG_GRN = 1,
        ACTUAL_PR = 2,
        REPLACEMENT = 3
}

enum SettlementType {
        CREDIT_NOTE = 1,
        REPLACEMENT = 2,
        AGAINST_GRN = 3
}

struct PurchaseOrder {
    1:i64 id,
    2:string poNumber,
    3:list<LineItem> lineitems,
    4:i64 supplierId,
    5:i64 warehouseId,
    6:i64 shippingWarehouseId,
    7:POStatus status,
    8:i64 createdAt,
    9:i64 updatedAt,
    10:double totalCost,
    11:double freightCharges,
    12:double realizedCost,
    13:double realizedFreightCharges,
    14:POType type,
    15:TaxType taxType,
    16:i64 warehouseAddressId
    17:i64 shippingWarehouseAddressId
    18:i64 buyerId
}

struct Purchase {
    1:i64 id,
    2:i64 poId,
    3:string invoiceNumber,
    4:i64 receivedOn,
    5:double freightCharges,
    6:string purchaseComments
}

struct PurchaseReturn {
    1:i64 id,
    2:i64 vendorId,
    3:i64 amount,
    4:i64 returnTimestamp,
    5:bool isSettled,
    6:PurchaseReturnType type,
    7:PurchaseReturnInventoryType returnInventoryType,
    8:SettlementType currentSettlementType,
    9:i64 latestSettlementDate,
    10:PrReasonType purchaseReturnType,
    11:string reasonText,
    12:string documentNumber,
    13:string createdBy,
    14:i64 unsettledAmount  
}

struct PurchaseReturnSettlement {
        1:i64 purchaseReturnId,
        2:SettlementType settlementType,
        3:i64 settlementAmount,
        4:i64 settlementDate,
        5:string settlementBy
        6:string documentNumber
}


struct Invoice {
    1:i64 id,
    2:string invoiceNumber,
    3:i64 date,
    4:i64 numItems,
    5:string receivedFrom,
    6:i64 supplierId,
    7:i64 warehouseId,
    8:i64 invoiceDate
}

exception PurchaseServiceException {
    1:GenericService.ExceptionType exceptionType,
    2:string message
}

service PurchaseService extends GenericService.GenericService {
    /**
    Creates a purchase order based on the data in the given purchase order object.
    This method populates a nummber of missing fields 
    */
    i64 createPurchaseOrder(1:PurchaseOrder purchaseOrder) throws (1:PurchaseServiceException e),
    
    /**
    Returns the purchase order with the given id. Throws an exception if there is no such purchase order.
    */
    PurchaseOrder getPurchaseOrder(1:i64 id) throws (1:PurchaseServiceException e),

    /**
    Returns a list of all the purchase orders in the given state
    */
    list<PurchaseOrder> getAllPurchaseOrders(1:POStatus status) throws (1:PurchaseServiceException e),
    
    /**
    Returns the supplier with the given order id. Throws an exception if there is no such supplier.
    */
    Supplier getSupplier(1:i64 id) throws (1:PurchaseServiceException e),
    
    /**
    Creates a purchase for the given purchase order.
    Throws an exception if no more purchases are allowed against the given purchase order.
    */
    i64 startPurchase(1:i64 purchaseOrderId, 2:string invoiceNumber, 3:double freightCharges, 4:string purchaseComments) throws (1:PurchaseServiceException e),
    
    /**
    Marks a purchase as complete and updates the receivedOn time.
    Throws an exception if no such purchase exists.
    */
    i64 closePurchase(1:i64 purchaseId) throws (1:PurchaseServiceException e),
    
    /**
    Returns all open or closed purchases for the given purchase order. Throws an exception if no such purchase order exists
    */
    list<Purchase> getAllPurchases(1:i64 purchaseOrderId, 2:bool open) throws (1:PurchaseServiceException e),
    
    /**
    Returns all purchases for the given purchase order. Throws an exception if no such purchase order exists
    */
    list<Purchase> getPurchasesForPO(1:i64 purchaseOrderId) throws (1:PurchaseServiceException e),

    /**
     * Returns the purchase order object for a given purchase
     */
    PurchaseOrder getPurchaseOrderForPurchase(1:i64 purchaseId);

    /**
     * Creates purchase order objects from pending orders
     */
    list<PurchaseOrder> getPendingPurchaseOrders(1:i64 warehouseId) throws (1:PurchaseServiceException e);

    /**
     * Returns all the valid suppliers with GST Codes
     */
    list<Supplier> getSuppliers() throws (1:PurchaseServiceException e);

    /**
     * Returns all the valid suppliers
     */
    list<Supplier> getAllSuppliers() throws (1:PurchaseServiceException e);

    /**
     * Fulfills a given purchase order with an item.
     */
    void fulfillPO(1:i64 purchaseOrderId, 2:i64 itemId, 3:i64 quantity) throws (1:PurchaseServiceException e);

    /**
     * Amends a PO as per the new lineitems passed 
     */
    void updatePurchaseOrder(1:PurchaseOrder purchaseOrder) throws (1:PurchaseServiceException e),

    /**
     * Fulfills a given purchase id with an item and its quantity.
     */
    void unFulfillPO(1:i64 purchaseId, 2:i64 itemId, 3:i64 quantity) throws (1:PurchaseServiceException e);
    
    /**
     * Fetches all invoices after a given date
     */
    list<Invoice> getInvoices(1:i64 date);

        /**
     * Fetches all invoices after a given date
     */
    list<Invoice> getInvoicesForWarehouse(1:i64 warehouseId, 2:i64 supplierId, 3:i64 date);

    /**
     * Creates an invoice object
     */
    void createInvoice(1:Invoice invoice) throws (1:PurchaseServiceException e);
    
    /**
     * Creates a supplier 
     */
    Supplier addSupplier(1:Supplier supplier);

    /**
     * Updates a supplier 
     */
    void updateSupplier(1:Supplier supplier);
    
    /**
     * Create a new Purchase Return
    */
        i64 createPurchaseReturn(1:PurchaseReturn purchaseReturn);
    
    /**
     * Create a new Purchase Return
    */
    void settlePurchaseReturn(1:i64 id);
    
    /**
     * Create a new Purchase Return
    */
    list<PurchaseReturn> getUnsettledPurchaseReturns();
    
    /**
     * Get invoice with given supplierId and invoiceNumber
    */
    list<PurchaseReturn> getInvoice(1:string invoiceNumber, 2:i64 supplierId);
    
    /**
     * Inserts new Invoice/LineItem/Purchase Entries for Billed Product done through Our External Billing
    **/
    i64 createPurchaseForOurExtBilling(1:string invoiceNumber, 2:double unitPrice, 3:double nlc, 4:i64 itemId);
    
    void fulfillPOForExtBilling(1:i64 itemId, 2:i64 quantity);
    
    /**
     * Marks a purchase order as closedcomplete and updates the receivedOn time.
    */
    void closePO(1:i64 poId) throws (1:PurchaseServiceException e),

    /**
     * Check if invoice is already received with given supplierId and invoiceNumber
    */
    bool isInvoiceReceived(1:string invoiceNumber, 2:i64 supplierId);
    
    /**
     * Change warehouseId of PO if no items have been received yet for the PO
    */
    void changeWarehouseForPO(1:i64 id, 2:i64 warehouseId) throws (1:PurchaseServiceException e);
    
    /**
     * Change status of PO 
    */
    void changePOStatus(1:i64 id, 2:POStatus poStatus)throws (1:PurchaseServiceException e);
    
    /**
     * Get Purchase Return from Id
    */
    PurchaseReturn getPurchaseReturn(1:i64 id)throws (1:PurchaseServiceException e);
    
    bool markPurchasereturnSettled(1:i64 id, 2:SettlementType settlementType, 3:string documentNumber, 4:string settlementBy, 5:i64 settledAmount) throws (1:PurchaseServiceException e);
    
    list<PurchaseReturnSettlement> getPrSettlementsForPurchaseReturn(1:i64 purchaseReturnId) throws (1:PurchaseServiceException e);
    
    void updatePurchaseReturn(1:PurchaseReturn purchaseReturn) throws (1:PurchaseServiceException e);
}