Add useful import snippets here

Program examples

Creating Customer Groups

next_token();//Group Code
if (code[0]) 
{
        if (!lookup(&ifdb[DRTYP], code))
                srec->drtype = ifdb[DRTYP].offset->ptr.record;
        else
        {
                struct s_sdrtyp *sdrtyp = recbuf[SDRTYP];
                getbuc(&fdb[DRTYP], IMPORT_DEFREC, sdrtyp);
                strncpy(sdrtyp->drtcode, code, sizeof(sdrtyp->drtcode)-1);
                strncpy(sdrtyp->drtname,"ADDED BY IMPORT",sizeof(sdrtyp->drtname)-1);
                addrec(&fdb[DRTYP], sdrtyp, drt_extnflds);
                printf("%s added group\n", code);
                
                if (lookup(&ifdb[DRTYP], code))
                        printf("Error adding group '%s'\n",code);
                else
                        srec->drtype = ifdb[DRTYP].offset->ptr.record;
        }
}

Creating Salespeople on the fly

next_token();// Account Dealer
if(!lookup(&ifdb[SMAN],code))
        srec->salesman = ifdb[SMAN].offset->ptr.record;
else if(code[0])
        {
        struct s_ssman *ssman = recbuf[SSMAN];
        getbuc(&fdb[SMAN],IMPORT_DEFREC,ssman);
        strncpy(ssman->smcode,code,sizeof(ssman->smcode)-1);
        strncpy(ssman->smname,"ZZ ADDED BY IMPORT",sizeof(ssman->smname)-1);
        addrec(&fdb[SMAN],ssman,sm_extnflds);
        if(!lookup(&ifdb[SMAN],code))
                {
                srec->salesman = ifdb[SMAN].offset->ptr.record;
                printf("Added salesman: '%s'\n",code);
                }
        else
                printf("Error adding salesman: '%s'\n",code);
                
        }

Creating customer records in the process of adding a customer record

if(!lookup(&ifdb[DEBTR],code))
        vrec->cust_pricing[0] = ifdb[DEBTR].offset->ptr.record;
else
        {
        // Need to create this customer
        S_CUSTOMER pricelist = {0};
        cpybuf(&pricelist,srec,fdb[DEBTR].bucsiz);
        getbuc(&fdb[DEBTR], IMPORT_DEFREC,srec);
        strncpy(srec->drcode,code,sizeof(srec->drcode)-1);
        strncpy(srec->nam_add[0],"ZZ PRICELIST ADDED BY IMPORT",sizeof(srec->nam_add[0])-1);
        addrec(&fdb[DEBTR], srec, dr_extnflds);
        cpybuf(srec,&pricelist,fdb[DEBTR].bucsiz);
                        
        if(!lookup(&ifdb[DEBTR],code))
                {
                vrec->cust_pricing[0] = ifdb[DEBTR].offset->ptr.record;
                printf("Added pricelist code: '%s'\n",code);
                }
        else
                printf("Error adding pricelist code: '%s'\n",code);
        }

Creating Suppliers

        getbuc(&fdb[CRED],IMPORT_DEFREC,scred);
        strncpy(scred->crcode,code,sizeof(scred->crcode)-1);
        strncpy(scred->crcoment,"ADDED BY STOCK IMPORT",sizeof(scred->crcoment)-1);
        addrec(&fdb[CRED],scred,cr_extnflds);
        if(!lookup(&ifdb[CRED],code))
        {
                sstock->ssupp[0].supp = ifdb[CRED].offset->ptr.record;
        }
        else
        {
                printf("Error adding %s supplier\n",code);
        }

ImportSnippets (last edited 2013-09-18 06:09:33 by localhost)